Commit: 20b39e4bd6ae85f30323c538efd612cb836b1eca Author: YimingWu Date: Tue Jul 28 12:14:42 2020 +0800 Branches: lanpr-under-gp https://developer.blender.org/rB20b39e4bd6ae85f30323c538efd612cb836b1eca
LineArt: Memory allocation now dynamically stretch each pool for better efficiency and large model handling. =================================================================== M source/blender/editors/include/ED_lineart.h M source/blender/editors/lineart/lineart_intern.h M source/blender/editors/lineart/lineart_util.c =================================================================== diff --git a/source/blender/editors/include/ED_lineart.h b/source/blender/editors/include/ED_lineart.h index 17a82862bd2..38586ffbf20 100644 --- a/source/blender/editors/include/ED_lineart.h +++ b/source/blender/editors/include/ED_lineart.h @@ -41,12 +41,12 @@ typedef struct LineartStaticMemPoolNode { Link item; + int size; int used_byte; /* User memory starts here */ } LineartStaticMemPoolNode; typedef struct LineartStaticMemPool { - int each_size; ListBase pools; SpinLock lock_mem; } LineartStaticMemPool; @@ -318,9 +318,7 @@ typedef struct LineartSharedResource { #define DBL_EDGE_LIM 1e-9 #define LRT_MEMORY_POOL_1MB 1048576 -#define LRT_MEMORY_POOL_128MB 134217728 -#define LRT_MEMORY_POOL_256MB 268435456 -#define LRT_MEMORY_POOL_512MB 536870912 +#define LRT_MEMORY_POOL_64MB 67108864 typedef enum eLineartCullState { LRT_CULL_DONT_CARE = 0, diff --git a/source/blender/editors/lineart/lineart_intern.h b/source/blender/editors/lineart/lineart_intern.h index eb8d467996d..5f2ad5e3add 100644 --- a/source/blender/editors/lineart/lineart_intern.h +++ b/source/blender/editors/lineart/lineart_intern.h @@ -53,7 +53,7 @@ void *list_append_pointer_static_pool(struct LineartStaticMemPool *mph, ListBase void *list_pop_pointer_no_free(ListBase *h); void list_remove_pointer_item_no_free(ListBase *h, LinkData *lip); -LineartStaticMemPoolNode *mem_new_static_pool(struct LineartStaticMemPool *smp); +LineartStaticMemPoolNode *mem_new_static_pool(struct LineartStaticMemPool *smp, int size); void *mem_static_aquire(struct LineartStaticMemPool *smp, int size); void *mem_static_aquire_thread(struct LineartStaticMemPool *smp, int size); void *mem_static_destroy(LineartStaticMemPool *smp); diff --git a/source/blender/editors/lineart/lineart_util.c b/source/blender/editors/lineart/lineart_util.c index 1f7836cf6d0..799bd24a9b8 100644 --- a/source/blender/editors/lineart/lineart_util.c +++ b/source/blender/editors/lineart/lineart_util.c @@ -85,9 +85,15 @@ void list_remove_pointer_item_no_free(ListBase *h, LinkData *lip) BLI_remlink(h, (void *)lip); } -LineartStaticMemPoolNode *mem_new_static_pool(LineartStaticMemPool *smp) +LineartStaticMemPoolNode *mem_new_static_pool(LineartStaticMemPool *smp, int size) { - LineartStaticMemPoolNode *smpn = MEM_callocN(LRT_MEMORY_POOL_128MB, "mempool"); + int set_size = size; + if (set_size < LRT_MEMORY_POOL_64MB) { + set_size = LRT_MEMORY_POOL_64MB; /* Prevent too many small allocations. */ + } + int total_size = size + sizeof(LineartStaticMemPoolNode); + LineartStaticMemPoolNode *smpn = MEM_callocN(total_size, "mempool"); + smpn->size = total_size; smpn->used_byte = sizeof(LineartStaticMemPoolNode); BLI_addhead(&smp->pools, smpn); return smpn; @@ -97,8 +103,8 @@ void *mem_static_aquire(LineartStaticMemPool *smp, int size) LineartStaticMemPoolNode *smpn = smp->pools.first; void *ret; - if (!smpn || (smpn->used_byte + size) > LRT_MEMORY_POOL_128MB) { - smpn = mem_new_static_pool(smp); + if (!smpn || (smpn->used_byte + size) > smpn->size) { + smpn = mem_new_static_pool(smp, size); } ret = ((unsigned char *)smpn) + smpn->used_byte; @@ -114,8 +120,8 @@ void *mem_static_aquire_thread(LineartStaticMemPool *smp, int size) BLI_spin_lock(&smp->lock_mem); - if (!smpn || (smpn->used_byte + size) > LRT_MEMORY_POOL_128MB) { - smpn = mem_new_static_pool(smp); + if (!smpn || (smpn->used_byte + size) > smpn->size) { + smpn = mem_new_static_pool(smp, size); } ret = ((unsigned char *)smpn) + smpn->used_byte; @@ -135,8 +141,6 @@ void *mem_static_destroy(LineartStaticMemPool *smp) MEM_freeN(smpn); } - smp->each_size = 0; - return ret; } _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org https://lists.blender.org/mailman/listinfo/bf-blender-cvs