Hash :
cae00d9b
Author :
Date :
2023-01-17T18:44:48
Vulkan: Cleanup shared ring buffer cmd alloc feature.
Changes:
- Simplified "SharedCommandBlockPool" interface.
Removed "ptrOut" and "usesCommandHeaderSizeForOffsetOut" parameters,
because "headerOut" has exactly the same value.
- Refactoring of "SharedCommandBlockPool" classes.
Some public methods made private, inline, or moved into ".cpp".
- Replace some getters with more specific/restrictive methods:
- "RingBufferAllocatorBuffer::getStorageSize()" -> "isEmpty()"
- "CommandBufferHelperCommon::getAllocator()"
-> "hasAllocatorLinks()"
- Added extra ASSERT()s.
- fixed typo "kMinRingBufferAllocatio(r)Capacity"
- other minor modifications.
Bug: angleproject:6401
Bug: b/256666069
Change-Id: I8f5c1c928bac5f8ecdfce7d411834f7ea39d11ac
Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/4218364
Commit-Queue: Igor Nazarov <i.nazarov@samsung.com>
Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org>
Reviewed-by: Charlie Lao <cclao@google.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 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
//
// 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.
//
// AllocatorHelperRing:
// Implements the ring buffer allocator helpers used in the command buffers.
//
#include "libANGLE/renderer/vulkan/AllocatorHelperRing.h"
#include "libANGLE/renderer/vulkan/SecondaryCommandBuffer.h"
namespace rx
{
namespace vk
{
void SharedCommandBlockAllocator::resetAllocator()
{
ASSERT(!mAllocator || !mAllocator->isShared());
if (mAllocSharedCP)
{
mAllocSharedCP->releaseAndUpdate(&mAllocReleaseCP);
mAllocSharedCP = nullptr;
}
ASSERT(!mAllocSharedCP && !mAllocReleaseCP.valid());
}
void SharedCommandBlockAllocator::attachAllocator(SharedCommandMemoryAllocator *allocator)
{
ASSERT(allocator);
ASSERT(!mAllocator);
mAllocator = allocator;
if (mAllocator->isShared())
{
mAllocator->releaseToSharedCP();
}
}
SharedCommandMemoryAllocator *SharedCommandBlockAllocator::detachAllocator(
bool isCommandBufferEmpty)
{
ASSERT(mAllocator);
if (!isCommandBufferEmpty)
{
// Must call reset() after detach from non-empty command buffer (OK to have an empty RP)
ASSERT(!mAllocSharedCP && !mAllocReleaseCP.valid());
mAllocSharedCP = mAllocator->acquireSharedCP();
mAllocReleaseCP = mAllocator->get().getReleaseCheckPoint();
}
SharedCommandMemoryAllocator *result = mAllocator;
mAllocator = nullptr;
return result;
}
void SharedCommandBlockPool::attachAllocator(SharedCommandMemoryAllocator *source)
{
ASSERT(source);
RingBufferAllocator &sourceIn = source->get();
ASSERT(sourceIn.valid());
ASSERT(mCommandBuffer->hasEmptyCommands());
ASSERT(mLastCommandBlock == nullptr);
ASSERT(mFinishedCommandSize == 0);
ASSERT(!mAllocator.valid());
mAllocator = std::move(sourceIn);
mAllocator.setFragmentReserve(kCommandHeaderSize);
pushNewCommandBlock(mAllocator.allocate(0));
mAllocator.setListener(this);
}
void SharedCommandBlockPool::detachAllocator(SharedCommandMemoryAllocator *destination)
{
ASSERT(destination);
RingBufferAllocator &destinationOut = destination->get();
ASSERT(!destinationOut.valid());
ASSERT(mAllocator.valid());
mAllocator.setListener(nullptr);
finishLastCommandBlock();
if (mFinishedCommandSize == 0)
{
mCommandBuffer->clearCommands();
}
else
{
mAllocator.setFragmentReserve(0);
(void)mAllocator.allocate(sizeof(kCommandHeaderSize));
}
destinationOut = std::move(mAllocator);
}
void SharedCommandBlockPool::pushNewCommandBlock(uint8_t *block)
{
mLastCommandBlock = block;
mCommandBuffer->pushToCommands(block);
}
void SharedCommandBlockPool::finishLastCommandBlock()
{
mFinishedCommandSize = getCommandSize();
terminateLastCommandBlock();
mLastCommandBlock = nullptr;
}
void SharedCommandBlockPool::onRingBufferNewFragment()
{
pushNewCommandBlock(mAllocator.getPointer());
}
void SharedCommandBlockPool::onRingBufferFragmentEnd()
{
finishLastCommandBlock();
}
void SharedCommandBlockPool::getMemoryUsageStats(size_t *usedMemoryOut,
size_t *allocatedMemoryOut) const
{
*usedMemoryOut = getCommandSize();
*allocatedMemoryOut = getCommandSize();
}
} // namespace vk
} // namespace rx