1 // 2 // Copyright 2022 The ANGLE Project Authors. All rights reserved. 3 // Use of this source code is governed by a BSD-style license that can be 4 // found in the LICENSE file. 5 // 6 // AllocatorHelperPool: 7 // Implements the pool allocator helpers used in the command buffers. 8 // 9 10 #include "libANGLE/renderer/vulkan/AllocatorHelperPool.h" 11 #include "libANGLE/renderer/vulkan/SecondaryCommandBuffer.h" 12 13 namespace rx 14 { 15 namespace vk 16 { 17 resetAllocator()18void DedicatedCommandBlockAllocator::resetAllocator() 19 { 20 mAllocator.pop(); 21 mAllocator.push(); 22 } 23 reset(CommandBufferCommandTracker * commandBufferTracker)24void DedicatedCommandBlockPool::reset(CommandBufferCommandTracker *commandBufferTracker) 25 { 26 mCommandBuffer->clearCommands(); 27 mCurrentWritePointer = nullptr; 28 mCurrentBytesRemaining = 0; 29 commandBufferTracker->reset(); 30 } 31 32 // Initialize the SecondaryCommandBuffer by setting the allocator it will use initialize(DedicatedCommandMemoryAllocator * allocator)33angle::Result DedicatedCommandBlockPool::initialize(DedicatedCommandMemoryAllocator *allocator) 34 { 35 ASSERT(allocator); 36 ASSERT(mCommandBuffer->hasEmptyCommands()); 37 mAllocator = allocator; 38 allocateNewBlock(); 39 // Set first command to Invalid to start 40 reinterpret_cast<CommandHeaderIDType &>(*mCurrentWritePointer) = 0; 41 42 return angle::Result::Continue; 43 } 44 empty() const45bool DedicatedCommandBlockPool::empty() const 46 { 47 return mCommandBuffer->checkEmptyForPoolAlloc(); 48 } 49 allocateNewBlock(size_t blockSize)50void DedicatedCommandBlockPool::allocateNewBlock(size_t blockSize) 51 { 52 ASSERT(mAllocator); 53 mCurrentWritePointer = mAllocator->fastAllocate(blockSize); 54 mCurrentBytesRemaining = blockSize; 55 mCommandBuffer->pushToCommands(mCurrentWritePointer); 56 } 57 getMemoryUsageStats(size_t * usedMemoryOut,size_t * allocatedMemoryOut) const58void DedicatedCommandBlockPool::getMemoryUsageStats(size_t *usedMemoryOut, 59 size_t *allocatedMemoryOut) const 60 { 61 mCommandBuffer->getMemoryUsageStatsForPoolAlloc(kBlockSize, usedMemoryOut, allocatedMemoryOut); 62 } 63 64 } // namespace vk 65 } // namespace rx 66