DRW: Replace BLI_mempool by BLI_memblock
authorClément Foucault <foucault.clem@gmail.com>
Tue, 7 May 2019 16:01:14 +0000 (18:01 +0200)
committerClément Foucault <foucault.clem@gmail.com>
Wed, 8 May 2019 15:49:28 +0000 (17:49 +0200)
This remove a avoid the big overhead present in BLI_mempool when it is
cleared.

source/blender/draw/intern/draw_manager.c
source/blender/draw/intern/draw_manager_data.c
source/blender/draw/intern/draw_manager_exec.c
source/blender/gpu/GPU_viewport.h
source/blender/gpu/intern/gpu_viewport.c

index 488027a..f0d802c 100644 (file)
@@ -23,7 +23,7 @@
 #include <stdio.h>
 
 #include "BLI_listbase.h"
-#include "BLI_mempool.h"
+#include "BLI_memblock.h"
 #include "BLI_rect.h"
 #include "BLI_string.h"
 #include "BLI_threads.h"
@@ -526,19 +526,19 @@ static void drw_viewport_cache_resize(void)
 
   if (DST.vmempool != NULL) {
     /* Release Image textures. */
-    BLI_mempool_iter iter;
+    BLI_memblock_iter iter;
     GPUTexture **tex;
-    BLI_mempool_iternew(DST.vmempool->images, &iter);
-    while ((tex = BLI_mempool_iterstep(&iter))) {
+    BLI_memblock_iternew(DST.vmempool->images, &iter);
+    while ((tex = BLI_memblock_iterstep(&iter))) {
       GPU_texture_free(*tex);
     }
 
-    BLI_mempool_clear_ex(DST.vmempool->calls, BLI_mempool_len(DST.vmempool->calls));
-    BLI_mempool_clear_ex(DST.vmempool->states, BLI_mempool_len(DST.vmempool->states));
-    BLI_mempool_clear_ex(DST.vmempool->shgroups, BLI_mempool_len(DST.vmempool->shgroups));
-    BLI_mempool_clear_ex(DST.vmempool->uniforms, BLI_mempool_len(DST.vmempool->uniforms));
-    BLI_mempool_clear_ex(DST.vmempool->passes, BLI_mempool_len(DST.vmempool->passes));
-    BLI_mempool_clear_ex(DST.vmempool->images, BLI_mempool_len(DST.vmempool->images));
+    BLI_memblock_clear(DST.vmempool->calls);
+    BLI_memblock_clear(DST.vmempool->states);
+    BLI_memblock_clear(DST.vmempool->shgroups);
+    BLI_memblock_clear(DST.vmempool->uniforms);
+    BLI_memblock_clear(DST.vmempool->passes);
+    BLI_memblock_clear(DST.vmempool->images);
   }
 
   DRW_instance_data_list_free_unused(DST.idatalist);
@@ -603,24 +603,22 @@ static void drw_viewport_var_init(void)
     DST.vmempool = GPU_viewport_mempool_get(DST.viewport);
 
     if (DST.vmempool->calls == NULL) {
-      DST.vmempool->calls = BLI_mempool_create(sizeof(DRWCall), 0, 512, 0);
+      DST.vmempool->calls = BLI_memblock_create(sizeof(DRWCall));
     }
     if (DST.vmempool->states == NULL) {
-      DST.vmempool->states = BLI_mempool_create(
-          sizeof(DRWCallState), 0, 512, BLI_MEMPOOL_ALLOW_ITER);
+      DST.vmempool->states = BLI_memblock_create(sizeof(DRWCallState));
     }
     if (DST.vmempool->shgroups == NULL) {
-      DST.vmempool->shgroups = BLI_mempool_create(sizeof(DRWShadingGroup), 0, 256, 0);
+      DST.vmempool->shgroups = BLI_memblock_create(sizeof(DRWShadingGroup));
     }
     if (DST.vmempool->uniforms == NULL) {
-      DST.vmempool->uniforms = BLI_mempool_create(sizeof(DRWUniform), 0, 512, 0);
+      DST.vmempool->uniforms = BLI_memblock_create(sizeof(DRWUniform));
     }
     if (DST.vmempool->passes == NULL) {
-      DST.vmempool->passes = BLI_mempool_create(sizeof(DRWPass), 0, 64, 0);
+      DST.vmempool->passes = BLI_memblock_create(sizeof(DRWPass));
     }
     if (DST.vmempool->images == NULL) {
-      DST.vmempool->images = BLI_mempool_create(
-          sizeof(GPUTexture *), 0, 512, BLI_MEMPOOL_ALLOW_ITER);
+      DST.vmempool->images = BLI_memblock_create(sizeof(GPUTexture *));
     }
 
     DST.idatalist = GPU_viewport_instance_data_list_get(DST.viewport);
index 90ffdc1..cb01b23 100644 (file)
@@ -37,6 +37,7 @@
 #include "BLI_hash.h"
 #include "BLI_link_utils.h"
 #include "BLI_mempool.h"
+#include "BLI_memblock.h"
 
 #include "GPU_buffers.h"
 
@@ -76,7 +77,7 @@ static void drw_shgroup_uniform_create_ex(DRWShadingGroup *shgroup,
                                           int length,
                                           int arraysize)
 {
-  DRWUniform *uni = BLI_mempool_alloc(DST.vmempool->uniforms);
+  DRWUniform *uni = BLI_memblock_alloc(DST.vmempool->uniforms);
   uni->location = loc;
   uni->type = type;
   uni->length = length;
@@ -390,7 +391,7 @@ static void drw_call_state_update_matflag(DRWCallState *state,
 
 static DRWCallState *drw_call_state_create(DRWShadingGroup *shgroup, float (*obmat)[4], Object *ob)
 {
-  DRWCallState *state = BLI_mempool_alloc(DST.vmempool->states);
+  DRWCallState *state = BLI_memblock_alloc(DST.vmempool->states);
   state->flag = 0;
   state->cache_id = 0;
   state->visibility_cb = NULL;
@@ -445,7 +446,7 @@ void DRW_shgroup_call_add(DRWShadingGroup *shgroup, GPUBatch *geom, float (*obma
   BLI_assert(geom != NULL);
   BLI_assert(ELEM(shgroup->type, DRW_SHG_NORMAL, DRW_SHG_FEEDBACK_TRANSFORM));
 
-  DRWCall *call = BLI_mempool_alloc(DST.vmempool->calls);
+  DRWCall *call = BLI_memblock_alloc(DST.vmempool->calls);
   call->state = drw_call_state_create(shgroup, obmat, NULL);
   call->type = DRW_CALL_SINGLE;
   call->single.geometry = geom;
@@ -463,7 +464,7 @@ void DRW_shgroup_call_range_add(
   BLI_assert(ELEM(shgroup->type, DRW_SHG_NORMAL, DRW_SHG_FEEDBACK_TRANSFORM));
   BLI_assert(v_count);
 
-  DRWCall *call = BLI_mempool_alloc(DST.vmempool->calls);
+  DRWCall *call = BLI_memblock_alloc(DST.vmempool->calls);
   call->state = drw_call_state_create(shgroup, obmat, NULL);
   call->type = DRW_CALL_RANGE;
   call->range.geometry = geom;
@@ -484,7 +485,7 @@ static void drw_shgroup_call_procedural_add_ex(DRWShadingGroup *shgroup,
 {
   BLI_assert(ELEM(shgroup->type, DRW_SHG_NORMAL, DRW_SHG_FEEDBACK_TRANSFORM));
 
-  DRWCall *call = BLI_mempool_alloc(DST.vmempool->calls);
+  DRWCall *call = BLI_memblock_alloc(DST.vmempool->calls);
   if (ob) {
     call->state = drw_call_state_object(shgroup, ob->obmat, ob);
   }
@@ -529,7 +530,7 @@ void DRW_shgroup_call_object_add_ex(
   BLI_assert(geom != NULL);
   BLI_assert(ELEM(shgroup->type, DRW_SHG_NORMAL, DRW_SHG_FEEDBACK_TRANSFORM));
 
-  DRWCall *call = BLI_mempool_alloc(DST.vmempool->calls);
+  DRWCall *call = BLI_memblock_alloc(DST.vmempool->calls);
   call->state = drw_call_state_object(shgroup, ob->obmat, ob);
   call->type = DRW_CALL_SINGLE;
   call->single.geometry = geom;
@@ -554,7 +555,7 @@ void DRW_shgroup_call_object_add_with_callback(DRWShadingGroup *shgroup,
   BLI_assert(geom != NULL);
   BLI_assert(ELEM(shgroup->type, DRW_SHG_NORMAL, DRW_SHG_FEEDBACK_TRANSFORM));
 
-  DRWCall *call = BLI_mempool_alloc(DST.vmempool->calls);
+  DRWCall *call = BLI_memblock_alloc(DST.vmempool->calls);
   call->state = drw_call_state_object(shgroup, ob->obmat, ob);
   call->state->visibility_cb = callback;
   call->state->user_data = user_data;
@@ -576,7 +577,7 @@ void DRW_shgroup_call_instances_add(DRWShadingGroup *shgroup,
   BLI_assert(geom != NULL);
   BLI_assert(ELEM(shgroup->type, DRW_SHG_NORMAL, DRW_SHG_FEEDBACK_TRANSFORM));
 
-  DRWCall *call = BLI_mempool_alloc(DST.vmempool->calls);
+  DRWCall *call = BLI_memblock_alloc(DST.vmempool->calls);
   call->state = drw_call_state_create(shgroup, obmat, NULL);
   call->type = DRW_CALL_INSTANCES;
   call->instances.geometry = geom;
@@ -597,7 +598,7 @@ void DRW_shgroup_call_object_instances_add(DRWShadingGroup *shgroup,
   BLI_assert(geom != NULL);
   BLI_assert(ELEM(shgroup->type, DRW_SHG_NORMAL, DRW_SHG_FEEDBACK_TRANSFORM));
 
-  DRWCall *call = BLI_mempool_alloc(DST.vmempool->calls);
+  DRWCall *call = BLI_memblock_alloc(DST.vmempool->calls);
   call->state = drw_call_state_object(shgroup, ob->obmat, ob);
   call->type = DRW_CALL_INSTANCES;
   call->instances.geometry = geom;
@@ -963,7 +964,7 @@ static void drw_shgroup_batching_init(DRWShadingGroup *shgroup,
 
 static DRWShadingGroup *drw_shgroup_create_ex(struct GPUShader *shader, DRWPass *pass)
 {
-  DRWShadingGroup *shgroup = BLI_mempool_alloc(DST.vmempool->shgroups);
+  DRWShadingGroup *shgroup = BLI_memblock_alloc(DST.vmempool->shgroups);
 
   BLI_LINKS_APPEND(&pass->shgroups, shgroup);
 
@@ -1016,7 +1017,7 @@ static DRWShadingGroup *drw_shgroup_material_inputs(DRWShadingGroup *grp,
       GPUTexture *tex = NULL;
 
       if (input->ima) {
-        GPUTexture **tex_ref = BLI_mempool_alloc(DST.vmempool->images);
+        GPUTexture **tex_ref = BLI_memblock_alloc(DST.vmempool->images);
 
         *tex_ref = tex = GPU_texture_from_blender(
             input->ima, input->iuser, GL_TEXTURE_2D, input->image_isdata);
@@ -1268,7 +1269,7 @@ DRWShadingGroup *DRW_shgroup_create_sub(DRWShadingGroup *shgroup)
   /* Remove this assertion if needed but implement the other cases first! */
   BLI_assert(shgroup->type == DRW_SHG_NORMAL);
 
-  DRWShadingGroup *shgroup_new = BLI_mempool_alloc(DST.vmempool->shgroups);
+  DRWShadingGroup *shgroup_new = BLI_memblock_alloc(DST.vmempool->shgroups);
 
   *shgroup_new = *shgroup;
   shgroup_new->uniforms = NULL;
@@ -1288,7 +1289,7 @@ DRWShadingGroup *DRW_shgroup_create_sub(DRWShadingGroup *shgroup)
 
 DRWPass *DRW_pass_create(const char *name, DRWState state)
 {
-  DRWPass *pass = BLI_mempool_alloc(DST.vmempool->passes);
+  DRWPass *pass = BLI_memblock_alloc(DST.vmempool->passes);
   pass->state = state;
   if (((G.debug_value > 20) && (G.debug_value < 30)) || (G.debug & G_DEBUG)) {
     BLI_strncpy(pass->name, name, MAX_PASS_NAME);
index 75f552d..e29b64c 100644 (file)
@@ -23,7 +23,7 @@
 #include "draw_manager.h"
 
 #include "BLI_math_bits.h"
-#include "BLI_mempool.h"
+#include "BLI_memblock.h"
 
 #include "BKE_global.h"
 
@@ -1392,10 +1392,10 @@ static void drw_update_view(void)
       DST.state_cache_id = 1;
       /* We must reset all CallStates to ensure that not
        * a single one stayed with cache_id equal to 1. */
-      BLI_mempool_iter iter;
+      BLI_memblock_iter iter;
       DRWCallState *state;
-      BLI_mempool_iternew(DST.vmempool->states, &iter);
-      while ((state = BLI_mempool_iterstep(&iter))) {
+      BLI_memblock_iternew(DST.vmempool->states, &iter);
+      while ((state = BLI_memblock_iterstep(&iter))) {
         state->cache_id = 0;
       }
     }
index 198a9ec..70626cc 100644 (file)
@@ -37,12 +37,12 @@ typedef struct GPUViewport GPUViewport;
 
 /* Contains memory pools information */
 typedef struct ViewportMemoryPool {
-  struct BLI_mempool *calls;
-  struct BLI_mempool *states;
-  struct BLI_mempool *shgroups;
-  struct BLI_mempool *uniforms;
-  struct BLI_mempool *passes;
-  struct BLI_mempool *images;
+  struct BLI_memblock *calls;
+  struct BLI_memblock *states;
+  struct BLI_memblock *shgroups;
+  struct BLI_memblock *uniforms;
+  struct BLI_memblock *passes;
+  struct BLI_memblock *images;
 } ViewportMemoryPool;
 
 /* All FramebufferLists are just the same pointers with different names */
index 558b3f0..88373dc 100644 (file)
@@ -27,7 +27,7 @@
 
 #include "BLI_listbase.h"
 #include "BLI_rect.h"
-#include "BLI_mempool.h"
+#include "BLI_memblock.h"
 
 #include "BIF_gl.h"
 
@@ -618,28 +618,28 @@ void GPU_viewport_free(GPUViewport *viewport)
   MEM_freeN(viewport->txl);
 
   if (viewport->vmempool.calls != NULL) {
-    BLI_mempool_destroy(viewport->vmempool.calls);
+    BLI_memblock_destroy(viewport->vmempool.calls);
   }
   if (viewport->vmempool.states != NULL) {
-    BLI_mempool_destroy(viewport->vmempool.states);
+    BLI_memblock_destroy(viewport->vmempool.states);
   }
   if (viewport->vmempool.shgroups != NULL) {
-    BLI_mempool_destroy(viewport->vmempool.shgroups);
+    BLI_memblock_destroy(viewport->vmempool.shgroups);
   }
   if (viewport->vmempool.uniforms != NULL) {
-    BLI_mempool_destroy(viewport->vmempool.uniforms);
+    BLI_memblock_destroy(viewport->vmempool.uniforms);
   }
   if (viewport->vmempool.passes != NULL) {
-    BLI_mempool_destroy(viewport->vmempool.passes);
+    BLI_memblock_destroy(viewport->vmempool.passes);
   }
   if (viewport->vmempool.images != NULL) {
-    BLI_mempool_iter iter;
+    BLI_memblock_iter iter;
     GPUTexture **tex;
-    BLI_mempool_iternew(viewport->vmempool.images, &iter);
-    while ((tex = BLI_mempool_iterstep(&iter))) {
+    BLI_memblock_iternew(viewport->vmempool.images, &iter);
+    while ((tex = BLI_memblock_iterstep(&iter))) {
       GPU_texture_free(*tex);
     }
-    BLI_mempool_destroy(viewport->vmempool.images);
+    BLI_memblock_destroy(viewport->vmempool.images);
   }
 
   DRW_instance_data_list_free(viewport->idatalist);