From d9479797853359493e8827a6b7e23c52161198bc Mon Sep 17 00:00:00 2001 From: yours3lf <0.tamas.marton@gmail.com> Date: Fri, 29 May 2020 21:49:16 +0100 Subject: [PATCH] added CPA num free block tracking --- driver/ConsecutivePoolAllocator.c | 21 ++++++++++++++++----- driver/ConsecutivePoolAllocator.h | 1 + driver/command.c | 2 ++ test/CPAtest/CPAtest.cpp | 3 --- 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/driver/ConsecutivePoolAllocator.c b/driver/ConsecutivePoolAllocator.c index 5b4f13a..7c068be 100644 --- a/driver/ConsecutivePoolAllocator.c +++ b/driver/ConsecutivePoolAllocator.c @@ -17,7 +17,8 @@ ConsecutivePoolAllocator createConsecutivePoolAllocator(char* b, unsigned bs, un .buf = b, .nextFreeBlock = (uint32_t*)b, .blockSize = bs, - .size = s + .size = s, + .numFreeBlocks = s / bs }; //initialize linked list of free pointers @@ -118,6 +119,8 @@ uint32_t consecutivePoolAllocate(ConsecutivePoolAllocator* pa, uint32_t numBlock //TODO debug stuff, not for release if(ptr) memset(ptr, 0, numBlocks * pa->blockSize); + pa->numFreeBlocks -= numBlocks; + return (char*)ptr - pa->buf; } @@ -194,6 +197,8 @@ void consecutivePoolFree(ConsecutivePoolAllocator* pa, void* p, uint32_t numBloc *(uint32_t*)listPtr = tmp; } } + + pa->numFreeBlocks += numBlocks; } uint32_t consecutivePoolReAllocate(ConsecutivePoolAllocator* pa, void* currentMem, uint32_t currNumBlocks) @@ -221,6 +226,8 @@ uint32_t consecutivePoolReAllocate(ConsecutivePoolAllocator* pa, void* currentMe pa->nextFreeBlock = *listPtr; } + pa->numFreeBlocks -= 1; + return (char*)currentMem - pa->buf; } @@ -235,6 +242,9 @@ uint32_t consecutivePoolReAllocate(ConsecutivePoolAllocator* pa, void* currentMe { return -1; } + + pa->numFreeBlocks -= 1; + //copy over old content memcpy(pa->buf + newMemOffset, currentMem, currNumBlocks * pa->blockSize); //free current element @@ -258,17 +268,18 @@ void CPAdebugPrint(ConsecutivePoolAllocator* pa) fprintf(stderr, "\nCPA Debug Print\n"); fprintf(stderr, "pa->buf %p\n", pa->buf); fprintf(stderr, "pa->nextFreeBlock %p\n", pa->nextFreeBlock); + fprintf(stderr, "pa->numFreeBlocks %u\n", pa->numFreeBlocks); - fprintf(stderr, "Linear walk:\n"); + //fprintf(stderr, "Linear walk:\n"); for(char* ptr = pa->buf; ptr != pa->buf + pa->size; ptr += pa->blockSize) { - fprintf(stderr, "%p: %p, ", ptr, *(uint32_t*)ptr); + //fprintf(stderr, "%p: %p, ", ptr, *(uint32_t*)ptr); } - fprintf(stderr, "\nLinked List walk:\n"); + //fprintf(stderr, "\nLinked List walk:\n"); for(uint32_t* ptr = pa->nextFreeBlock; ptr; ptr = *ptr) { - fprintf(stderr, "%p: %p, ", ptr, *ptr); + //fprintf(stderr, "%p: %p, ", ptr, *ptr); } fprintf(stderr, "\n"); } diff --git a/driver/ConsecutivePoolAllocator.h b/driver/ConsecutivePoolAllocator.h index 8cf03f6..0386b52 100644 --- a/driver/ConsecutivePoolAllocator.h +++ b/driver/ConsecutivePoolAllocator.h @@ -14,6 +14,7 @@ typedef struct ConsecutivePoolAllocator uint32_t* nextFreeBlock; unsigned blockSize; unsigned size; //size is exact multiple of block size + unsigned numFreeBlocks; } ConsecutivePoolAllocator; ConsecutivePoolAllocator createConsecutivePoolAllocator(char* b, unsigned bs, unsigned s); diff --git a/driver/command.c b/driver/command.c index dd429c9..c0ca1c3 100644 --- a/driver/command.c +++ b/driver/command.c @@ -655,6 +655,8 @@ VKAPI_ATTR VkResult VKAPI_CALL RPIFUNC(vkQueueSubmit)( //advance in linked list marker = marker->nextMarkerOffset == -1 ? 0 : getCPAptrFromOffset(cmdbuf->binCl.CPA, marker->nextMarkerOffset + cmdbuf->binCl.offset); } + + //CPAdebugPrint(cmdbuf->binCl.CPA); } for(int c = 0; c < pSubmits->commandBufferCount; ++c) diff --git a/test/CPAtest/CPAtest.cpp b/test/CPAtest/CPAtest.cpp index fa5b43c..8cc70c0 100644 --- a/test/CPAtest/CPAtest.cpp +++ b/test/CPAtest/CPAtest.cpp @@ -121,9 +121,6 @@ void reallocTest() consecutivePoolFree(&cpa, getCPAptrFromOffset(&cpa, mem4), 1); CPAdebugPrint(&cpa); - consecutivePoolFree(&cpa, getCPAptrFromOffset(&cpa, mem5), 1); - CPAdebugPrint(&cpa); - //mem2 = consecutivePoolReAllocate(&cpa, getCPAptrFromOffset(&cpa, mem2), 1); //CPAdebugPrint(&cpa);