From 3860f115c05f9c3bc2fae2edc332e910763f8d3a Mon Sep 17 00:00:00 2001 From: yours3lf <0.tamas.marton@gmail.com> Date: Fri, 29 May 2020 21:45:23 +0100 Subject: [PATCH] fixed cpa alloc strategy so now we get away with a lot less --- driver/ConsecutivePoolAllocator.c | 27 ++++++++++++++++++++++++--- driver/command.c | 4 ++-- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/driver/ConsecutivePoolAllocator.c b/driver/ConsecutivePoolAllocator.c index 113e271..5b4f13a 100644 --- a/driver/ConsecutivePoolAllocator.c +++ b/driver/ConsecutivePoolAllocator.c @@ -60,8 +60,6 @@ uint32_t consecutivePoolAllocate(ConsecutivePoolAllocator* pa, uint32_t numBlock return -1; //no free blocks } - //TODO change strategy to search for the blocks that are located closest to the start of the buffer - //but still are big enough in size for(; ptr; ptr = *ptr) { uint32_t found = 1; @@ -84,7 +82,30 @@ uint32_t consecutivePoolAllocate(ConsecutivePoolAllocator* pa, uint32_t numBlock if(found) { //set the next free block to the one that the last block we allocated points to - pa->nextFreeBlock = *(uint32_t*)((char*)ptr + (numBlocks - 1) * pa->blockSize); + uint32_t* nextFreeBlockCandidate = *(uint32_t*)((char*)ptr + (numBlocks - 1) * pa->blockSize); + + if(pa->nextFreeBlock == ptr) + { + pa->nextFreeBlock = nextFreeBlockCandidate; + break; + } + + uint32_t* prevPtr = pa->nextFreeBlock; + uint32_t* currPtr = prevPtr; + for(; currPtr; currPtr = *currPtr) + { + if(currPtr == ptr) + { + break; + } + + prevPtr = currPtr; + } + + assert(currPtr); + + *prevPtr = nextFreeBlockCandidate; + break; } diff --git a/driver/command.c b/driver/command.c index 29691cd..dd429c9 100644 --- a/driver/command.c +++ b/driver/command.c @@ -52,8 +52,8 @@ VKAPI_ATTR VkResult VKAPI_CALL RPIFUNC(vkCreateCommandPool)( //initial number of command buffers to hold int numCommandBufs = 128; //TODO uniforms might need to realloc, which should be handled properly - int consecutiveBlockSize = ARM_PAGE_SIZE * 20; - int consecutiveBlockNumber = 256; + int consecutiveBlockSize = ARM_PAGE_SIZE;// * 20; + int consecutiveBlockNumber = 64; //int numCommandBufs = 30; //int consecutiveBlockSize = getCPABlockSize(256); //int consecutiveBlockNumber = 30;