[Bf-blender-cvs] [87e3ea74d92] temp-lineart-contained: LineArt: Spreading load for multithread loading of geometry.

YimingWu noreply at git.blender.org
Wed Apr 14 08:27:29 CEST 2021


Commit: 87e3ea74d92ba5bfa1d1a05418bda88074e1e3f4
Author: YimingWu
Date:   Wed Apr 14 14:27:13 2021 +0800
Branches: temp-lineart-contained
https://developer.blender.org/rB87e3ea74d92ba5bfa1d1a05418bda88074e1e3f4

LineArt: Spreading load for multithread loading of geometry.

===================================================================

M	source/blender/gpencil_modifiers/intern/lineart/MOD_lineart.h
M	source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c

===================================================================

diff --git a/source/blender/gpencil_modifiers/intern/lineart/MOD_lineart.h b/source/blender/gpencil_modifiers/intern/lineart/MOD_lineart.h
index 84a6530e43b..413870de28e 100644
--- a/source/blender/gpencil_modifiers/intern/lineart/MOD_lineart.h
+++ b/source/blender/gpencil_modifiers/intern/lineart/MOD_lineart.h
@@ -385,7 +385,10 @@ typedef struct LineartObjectInfo {
 typedef struct LineartObjectLoadTaskInfo {
   struct LineartRenderBuffer *rb;
   struct Depsgraph *dg;
-  LineartObjectInfo *pending; /* LinkNode styled list */
+  /* LinkNode styled list */
+  LineartObjectInfo *pending;
+  /* Used to spread the load across several threads. This can not overflow. */
+  long unsigned int total_faces;
 } LineartObjectLoadTaskInfo;
 
 /**
diff --git a/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c b/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c
index 89e94b48086..e3091a484ea 100644
--- a/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c
+++ b/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c
@@ -29,6 +29,8 @@
 #include "BLI_task.h"
 #include "BLI_utildefines.h"
 
+#include "PIL_time.h"
+
 #include "BKE_camera.h"
 #include "BKE_collection.h"
 #include "BKE_customdata.h"
@@ -1853,6 +1855,24 @@ static int lineart_usage_check(Collection *c, Object *ob, LineartRenderBuffer *_
   return OBJECT_LRT_INHERIT;
 }
 
+static void lineart_geometry_load_assign_thread(LineartObjectLoadTaskInfo *olti_list,
+                                                LineartObjectInfo *obi,
+                                                int thread_count,
+                                                int this_face_count)
+{
+  LineartObjectLoadTaskInfo *use_olti = olti_list;
+  long unsigned int min_face = use_olti->total_faces;
+  for (int i = 0; i < thread_count; i++) {
+    if (olti_list[i].total_faces < min_face) {
+      min_face = olti_list[i].total_faces;
+      use_olti = &olti_list[i];
+    }
+  }
+  use_olti->total_faces += this_face_count;
+  obi->next = use_olti->pending;
+  use_olti->pending = obi;
+}
+
 static void lineart_main_load_geometries(
     Depsgraph *depsgraph,
     Scene *scene,
@@ -1869,6 +1889,12 @@ static void lineart_main_load_geometries(
 
   double asp = ((double)rb->w / (double)rb->h);
 
+  double t_start;
+
+  if (G.debug_value == 4000) {
+    t_start = PIL_check_seconds_timer();
+  }
+
   if (cam->type == CAM_PERSP) {
     if (asp < 1) {
       fov /= asp;
@@ -1905,7 +1931,6 @@ static void lineart_main_load_geometries(
   LineartObjectLoadTaskInfo *olti = lineart_mem_aquire(
       &rb->render_data_pool, sizeof(LineartObjectLoadTaskInfo) * thread_count);
 
-  int to_thread = 0;
   DEG_OBJECT_ITER_BEGIN (depsgraph, ob, flags) {
     LineartObjectInfo *obi = lineart_mem_aquire(&rb->render_data_pool, sizeof(LineartObjectInfo));
     obi->override_usage = lineart_usage_check(scene->master_collection, ob, rb);
@@ -1970,13 +1995,7 @@ static void lineart_main_load_geometries(
 
     obi->original_bm = bm;
     obi->original_ob = (ob->id.orig_id ? (Object *)ob->id.orig_id : (Object *)ob);
-    obi->next = olti[to_thread].pending;
-    olti[to_thread].pending = obi;
-
-    to_thread++;
-    if (to_thread >= thread_count) {
-      to_thread = 0;
-    }
+    lineart_geometry_load_assign_thread(olti, obi, thread_count, bm->totface);
   }
   DEG_OBJECT_ITER_END;
 
@@ -2008,6 +2027,11 @@ static void lineart_main_load_geometries(
       lineart_finalize_object_edge_list(rb, obi);
     }
   }
+
+  if (G.debug_value == 4000) {
+    double t_elapsed = PIL_check_seconds_timer() - t_start;
+    printf("Line art loading time: %lf\n", t_elapsed);
+  }
 }
 
 /**
@@ -3796,6 +3820,12 @@ bool MOD_lineart_compute_feature_lines(Depsgraph *depsgraph, LineartGpencilModif
   Scene *scene = DEG_get_evaluated_scene(depsgraph);
   int intersections_only = 0; /* Not used right now, but preserve for future. */
 
+  double t_start;
+
+  if (G.debug_value == 4000) {
+    t_start = PIL_check_seconds_timer();
+  }
+
   if (!scene->camera) {
     return false;
   }
@@ -3889,6 +3919,9 @@ bool MOD_lineart_compute_feature_lines(Depsgraph *depsgraph, LineartGpencilModif
 
   if (G.debug_value == 4000) {
     lineart_count_and_print_render_buffer_memory(rb);
+
+    double t_elapsed = PIL_check_seconds_timer() - t_start;
+    printf("Line art total time: %lf\n", t_elapsed);
   }
 
   return true;



More information about the Bf-blender-cvs mailing list