diff --git a/driver/ConsecutivePoolAllocator.c b/driver/ConsecutivePoolAllocator.c index e736767..b67a0d3 100644 --- a/driver/ConsecutivePoolAllocator.c +++ b/driver/ConsecutivePoolAllocator.c @@ -48,7 +48,7 @@ void* consecutivePoolAllocate(ConsecutivePoolAllocator* pa, uint32_t numBlocks) { assert(pa->buf); -// fprintf(stderr, "pa->nextFreeBlock %u\n", pa->nextFreeBlock); + CPAdebugPrint(pa); if(!pa->nextFreeBlock) { @@ -148,6 +148,8 @@ void consecutivePoolFree(ConsecutivePoolAllocator* pa, void* p, uint32_t numBloc //else it frees current block and allocates a new one void* consecutivePoolReAllocate(ConsecutivePoolAllocator* pa, void* currentMem, uint32_t currNumBlocks) { + fprintf(stderr, "CPA realloc\n"); + currentMem = (char*)currentMem - 4; if(pa->nextFreeBlock == (uint32_t*)((char*)currentMem + currNumBlocks * pa->blockSize)) @@ -168,3 +170,23 @@ void* consecutivePoolReAllocate(ConsecutivePoolAllocator* pa, void* currentMem, return newContents; } } + +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, "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, "\nLinked List walk:\n"); + for(uint32_t* ptr = pa->nextFreeBlock; ptr; ptr = *ptr) + { + fprintf(stderr, "%p: %p, ", ptr, *ptr); + } + fprintf(stderr, "\n"); +} diff --git a/driver/ConsecutivePoolAllocator.h b/driver/ConsecutivePoolAllocator.h index 2a19a27..3712146 100644 --- a/driver/ConsecutivePoolAllocator.h +++ b/driver/ConsecutivePoolAllocator.h @@ -21,7 +21,7 @@ void destroyConsecutivePoolAllocator(ConsecutivePoolAllocator* pa); void* consecutivePoolAllocate(ConsecutivePoolAllocator* pa, uint32_t numBlocks); void consecutivePoolFree(ConsecutivePoolAllocator* pa, void* p, uint32_t numBlocks); void* consecutivePoolReAllocate(ConsecutivePoolAllocator* pa, void* currentMem, uint32_t currNumBlocks); -void debugPrint(ConsecutivePoolAllocator*, const char* text); +void CPAdebugPrint(ConsecutivePoolAllocator* pa); #if defined (__cplusplus) } diff --git a/driver/descriptorSet.c b/driver/descriptorSet.c index 45c7124..3aa462b 100644 --- a/driver/descriptorSet.c +++ b/driver/descriptorSet.c @@ -54,12 +54,19 @@ VKAPI_ATTR VkResult VKAPI_CALL rpi_vkCreateDescriptorPool( dp->bufferDescriptorCPA = 0; dp->texelBufferDescriptorCPA = 0; - void* memem = ALLOCATE(sizeof(mapElem)*(imageDescriptorCount + bufferDescriptorCount + texelBufferDescriptorCount), 1, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); +// fprintf(stderr, "imageDescriptorCount %u\n", imageDescriptorCount); +// fprintf(stderr, "bufferDescriptorCount %u\n", bufferDescriptorCount); +// fprintf(stderr, "texelBufferDescriptorCount %u\n", texelBufferDescriptorCount); + + + uint32_t mapElemBlockSize = sizeof(mapElem); + uint32_t mapBufSize = mapElemBlockSize * (imageDescriptorCount + bufferDescriptorCount + texelBufferDescriptorCount); + void* memem = ALLOCATE(mapBufSize, 1, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); if(!memem) { return VK_ERROR_OUT_OF_HOST_MEMORY; } - dp->mapElementCPA = createConsecutivePoolAllocator(memem, sizeof(mapElem), sizeof(mapElem) * (imageDescriptorCount + bufferDescriptorCount + texelBufferDescriptorCount)); + dp->mapElementCPA = createConsecutivePoolAllocator(memem, mapElemBlockSize, mapBufSize); if(imageDescriptorCount > 0) { @@ -69,12 +76,13 @@ VKAPI_ATTR VkResult VKAPI_CALL rpi_vkCreateDescriptorPool( return VK_ERROR_OUT_OF_HOST_MEMORY; } - void* mem = ALLOCATE(sizeof(_descriptorImage)*imageDescriptorCount, 1, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); + uint32_t blockSize = sizeof(_descriptorImage); + void* mem = ALLOCATE(blockSize*imageDescriptorCount, 1, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); if(!mem) { return VK_ERROR_OUT_OF_HOST_MEMORY; } - *dp->imageDescriptorCPA = createConsecutivePoolAllocator(mem, sizeof(_descriptorImage), sizeof(_descriptorImage) * imageDescriptorCount); + *dp->imageDescriptorCPA = createConsecutivePoolAllocator(mem, blockSize, blockSize * imageDescriptorCount); } if(bufferDescriptorCount > 0) @@ -85,12 +93,13 @@ VKAPI_ATTR VkResult VKAPI_CALL rpi_vkCreateDescriptorPool( return VK_ERROR_OUT_OF_HOST_MEMORY; } - void* mem = ALLOCATE(sizeof(_descriptorBuffer)*bufferDescriptorCount, 1, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); + uint32_t blockSize = sizeof(_descriptorBuffer); + void* mem = ALLOCATE(blockSize*bufferDescriptorCount, 1, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); if(!mem) { return VK_ERROR_OUT_OF_HOST_MEMORY; } - *dp->bufferDescriptorCPA = createConsecutivePoolAllocator(mem, sizeof(_descriptorBuffer), sizeof(_descriptorBuffer) * bufferDescriptorCount); + *dp->bufferDescriptorCPA = createConsecutivePoolAllocator(mem, blockSize, blockSize * bufferDescriptorCount); } if(texelBufferDescriptorCount > 0) @@ -101,12 +110,13 @@ VKAPI_ATTR VkResult VKAPI_CALL rpi_vkCreateDescriptorPool( return VK_ERROR_OUT_OF_HOST_MEMORY; } - void* mem = ALLOCATE(sizeof(_descriptorTexelBuffer)*texelBufferDescriptorCount, 1, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); + uint32_t blockSize = sizeof(_descriptorBuffer); + void* mem = ALLOCATE(blockSize*texelBufferDescriptorCount, 1, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); if(!mem) { return VK_ERROR_OUT_OF_HOST_MEMORY; } - *dp->texelBufferDescriptorCPA = createConsecutivePoolAllocator(mem, sizeof(_descriptorTexelBuffer), sizeof(_descriptorTexelBuffer) * texelBufferDescriptorCount); + *dp->texelBufferDescriptorCPA = createConsecutivePoolAllocator(mem, blockSize, blockSize * texelBufferDescriptorCount); } *pDescriptorPool = dp; @@ -165,6 +175,10 @@ VKAPI_ATTR VkResult VKAPI_CALL rpi_vkAllocateDescriptorSets( ds->bufferDescriptors = 0; ds->texelBufferDescriptors = 0; +// fprintf(stderr, "imageDescriptorCount %u\n", imageDescriptorCount); +// fprintf(stderr, "bufferDescriptorCount %u\n", bufferDescriptorCount); +// fprintf(stderr, "texelBufferDescriptorCount %u\n", texelBufferDescriptorCount); + if(imageDescriptorCount > 0) { ds->imageDescriptors = consecutivePoolAllocate(dp->imageDescriptorCPA, imageDescriptorCount);