[Bf-blender-cvs] [9f60188cd80] master: Cleanup: Use ListBase in various places in line art.

YimingWu noreply at git.blender.org
Tue May 25 17:34:10 CEST 2021


Commit: 9f60188cd805d10155c79ddb99adb703d6da7ba1
Author: YimingWu
Date:   Tue May 25 23:32:04 2021 +0800
Branches: master
https://developer.blender.org/rB9f60188cd805d10155c79ddb99adb703d6da7ba1

Cleanup: Use ListBase in various places in line art.

This clarifies the data structures for storing edges
for different calculation stages.

Reviewed By: Sebastian Parborg (zeddb)

Differential Revision: https://developer.blender.org/D11386

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

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

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

diff --git a/source/blender/gpencil_modifiers/intern/lineart/MOD_lineart.h b/source/blender/gpencil_modifiers/intern/lineart/MOD_lineart.h
index 56b1ff87f0b..e679dce2f2d 100644
--- a/source/blender/gpencil_modifiers/intern/lineart/MOD_lineart.h
+++ b/source/blender/gpencil_modifiers/intern/lineart/MOD_lineart.h
@@ -237,31 +237,14 @@ typedef struct LineartRenderBuffer {
 
   int triangle_size;
 
-  unsigned int contour_count;
-  unsigned int contour_processed;
-  LineartEdge *contour_managed;
-  /** A single linked list (cast to #LinkNode). */
-  LineartEdge *contours;
-
-  unsigned int intersection_count;
-  unsigned int intersection_processed;
-  LineartEdge *intersection_managed;
-  LineartEdge *intersection_lines;
-
-  unsigned int crease_count;
-  unsigned int crease_processed;
-  LineartEdge *crease_managed;
-  LineartEdge *crease_lines;
-
-  unsigned int material_line_count;
-  unsigned int material_processed;
-  LineartEdge *material_managed;
-  LineartEdge *material_lines;
-
-  unsigned int edge_mark_count;
-  unsigned int edge_mark_processed;
-  LineartEdge *edge_mark_managed;
-  LineartEdge *edge_marks;
+  /* Although using ListBase here, LineartEdge is single linked list.
+   * list.last is used to store worker progress along the list.
+   * See lineart_main_occlusion_begin() for more info. */
+  ListBase contour;
+  ListBase intersection;
+  ListBase crease;
+  ListBase material;
+  ListBase edge_mark;
 
   ListBase chains;
 
@@ -334,20 +317,13 @@ typedef struct LineartRenderTaskInfo {
 
   int thread_id;
 
-  LineartEdge *contour;
-  LineartEdge *contour_end;
-
-  LineartEdge *intersection;
-  LineartEdge *intersection_end;
-
-  LineartEdge *crease;
-  LineartEdge *crease_end;
-
-  LineartEdge *material;
-  LineartEdge *material_end;
-
-  LineartEdge *edge_mark;
-  LineartEdge *edge_mark_end;
+  /* These lists only denote the part of the main edge list that the thread should iterate over.
+   * Be careful to not iterate outside of these bounds as it is not thread safe to do so. */
+  ListBase contour;
+  ListBase intersection;
+  ListBase crease;
+  ListBase material;
+  ListBase edge_mark;
 
 } LineartRenderTaskInfo;
 
diff --git a/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c b/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c
index d43b9a3426f..ae8157e1a97 100644
--- a/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c
+++ b/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c
@@ -376,18 +376,18 @@ static int lineart_occlusion_make_task_info(LineartRenderBuffer *rb, LineartRend
   BLI_spin_lock(&rb->lock_task);
 
 #define LRT_ASSIGN_OCCLUSION_TASK(name) \
-  if (rb->name##_managed) { \
-    data = rb->name##_managed; \
-    rti->name = (void *)data; \
+  if (rb->name.last) { \
+    data = rb->name.last; \
+    rti->name.first = (void *)data; \
     for (i = 0; i < LRT_THREAD_EDGE_COUNT && data; i++) { \
       data = data->next; \
     } \
-    rti->name##_end = data; \
-    rb->name##_managed = data; \
+    rti->name.last = data; \
+    rb->name.last = data; \
     res = 1; \
   } \
   else { \
-    rti->name = NULL; \
+    rti->name.first = rti->name.last = NULL; \
   }
 
   LRT_ASSIGN_OCCLUSION_TASK(contour);
@@ -410,23 +410,23 @@ static void lineart_occlusion_worker(TaskPool *__restrict UNUSED(pool), LineartR
 
   while (lineart_occlusion_make_task_info(rb, rti)) {
 
-    for (eip = rti->contour; eip && eip != rti->contour_end; eip = eip->next) {
+    for (eip = rti->contour.first; eip && eip != rti->contour.last; eip = eip->next) {
       lineart_occlusion_single_line(rb, eip, rti->thread_id);
     }
 
-    for (eip = rti->crease; eip && eip != rti->crease_end; eip = eip->next) {
+    for (eip = rti->crease.first; eip && eip != rti->crease.last; eip = eip->next) {
       lineart_occlusion_single_line(rb, eip, rti->thread_id);
     }
 
-    for (eip = rti->intersection; eip && eip != rti->intersection_end; eip = eip->next) {
+    for (eip = rti->intersection.first; eip && eip != rti->intersection.last; eip = eip->next) {
       lineart_occlusion_single_line(rb, eip, rti->thread_id);
     }
 
-    for (eip = rti->material; eip && eip != rti->material_end; eip = eip->next) {
+    for (eip = rti->material.first; eip && eip != rti->material.last; eip = eip->next) {
       lineart_occlusion_single_line(rb, eip, rti->thread_id);
     }
 
-    for (eip = rti->edge_mark; eip && eip != rti->edge_mark_end; eip = eip->next) {
+    for (eip = rti->edge_mark.first; eip && eip != rti->edge_mark.last; eip = eip->next) {
       lineart_occlusion_single_line(rb, eip, rti->thread_id);
     }
   }
@@ -444,11 +444,13 @@ static void lineart_main_occlusion_begin(LineartRenderBuffer *rb)
                                            "Task Pool");
   int i;
 
-  rb->contour_managed = rb->contours;
-  rb->crease_managed = rb->crease_lines;
-  rb->intersection_managed = rb->intersection_lines;
-  rb->material_managed = rb->material_lines;
-  rb->edge_mark_managed = rb->edge_marks;
+  /* The "last" entry is used to store worker progress in the whole list.
+   * These list themselves are single-direction linked, with list.first being the head. */
+  rb->contour.last = rb->contour.first;
+  rb->crease.last = rb->crease.first;
+  rb->intersection.last = rb->intersection.first;
+  rb->material.last = rb->material.first;
+  rb->edge_mark.last = rb->edge_mark.first;
 
   TaskPool *tp = BLI_task_pool_create(NULL, TASK_PRIORITY_HIGH);
 
@@ -853,7 +855,7 @@ static void lineart_triangle_cull_single(LineartRenderBuffer *rb,
         INCREASE_EDGE
         if (allow_boundaries) {
           e->flags = LRT_EDGE_FLAG_CONTOUR;
-          lineart_prepend_edge_direct(&rb->contours, e);
+          lineart_prepend_edge_direct(&rb->contour.first, e);
         }
         /* NOTE: inverting `e->v1/v2` (left/right point) doesn't matter as long as
          * `tri->edge` and `tri->v` has the same sequence. and the winding direction
@@ -902,7 +904,7 @@ static void lineart_triangle_cull_single(LineartRenderBuffer *rb,
         INCREASE_EDGE
         if (allow_boundaries) {
           e->flags = LRT_EDGE_FLAG_CONTOUR;
-          lineart_prepend_edge_direct(&rb->contours, e);
+          lineart_prepend_edge_direct(&rb->contour.first, e);
         }
         e->v1 = &vt[0];
         e->v2 = &vt[1];
@@ -943,7 +945,7 @@ static void lineart_triangle_cull_single(LineartRenderBuffer *rb,
         INCREASE_EDGE
         if (allow_boundaries) {
           e->flags = LRT_EDGE_FLAG_CONTOUR;
-          lineart_prepend_edge_direct(&rb->contours, e);
+          lineart_prepend_edge_direct(&rb->contour.first, e);
         }
         e->v1 = &vt[1];
         e->v2 = &vt[0];
@@ -1018,7 +1020,7 @@ static void lineart_triangle_cull_single(LineartRenderBuffer *rb,
         INCREASE_EDGE
         if (allow_boundaries) {
           e->flags = LRT_EDGE_FLAG_CONTOUR;
-          lineart_prepend_edge_direct(&rb->contours, e);
+          lineart_prepend_edge_direct(&rb->contour.first, e);
         }
         e->v1 = &vt[1];
         e->v2 = &vt[0];
@@ -1070,7 +1072,7 @@ static void lineart_triangle_cull_single(LineartRenderBuffer *rb,
         INCREASE_EDGE
         if (allow_boundaries) {
           e->flags = LRT_EDGE_FLAG_CONTOUR;
-          lineart_prepend_edge_direct(&rb->contours, e);
+          lineart_prepend_edge_direct(&rb->contour.first, e);
         }
         e->v1 = &vt[1];
         e->v2 = &vt[0];
@@ -1118,7 +1120,7 @@ static void lineart_triangle_cull_single(LineartRenderBuffer *rb,
         INCREASE_EDGE
         if (allow_boundaries) {
           e->flags = LRT_EDGE_FLAG_CONTOUR;
-          lineart_prepend_edge_direct(&rb->contours, e);
+          lineart_prepend_edge_direct(&rb->contour.first, e);
         }
         e->v1 = &vt[1];
         e->v2 = &vt[0];
@@ -1431,19 +1433,19 @@ static void lineart_add_edge_to_list(LineartRenderBuffer *rb, LineartEdge *e)
 {
   switch (e->flags) {
     case LRT_EDGE_FLAG_CONTOUR:
-      lineart_prepend_edge_direct(&rb->contours, e);
+      lineart_prepend_edge_direct(&rb->contour.first, e);
       break;
     case LRT_EDGE_FLAG_CREASE:
-      lineart_prepend_edge_direct(&rb->crease_lines, e);
+      lineart_prepend_edge_direct(&rb->crease.first, e);
       break;
     case LRT_EDGE_FLAG_MATERIAL:
-      lineart_prepend_edge_direct(&rb->material_lines, e);
+      lineart_prepend_edge_direct(&rb->material.first, e);
       break;
     case LRT_EDGE_FLAG_EDGE_MARK:
-      lineart_prepend_edge_direct(&rb->edge_marks, e);
+      lineart_prepend_edge_direct(&rb->edge_mark.first, e);
       break;
     case LRT_EDGE_FLAG_INTERSECTION:
-      lineart_prepend_edge_direct(&rb->intersection_lines, e);
+      lineart_prepend_edge_direct(&rb->intersection.first, e);
       break;
   }
 }
@@ -2497,7 +2499,7 @@ static LineartEdge *lineart_triangle_intersect(LineartRenderBuffer *rb,
   BLI_addtail(&result->segments, es);
   /* Don't need to OR flags right now, just a type mark. */
   result->flags = LRT_EDGE_FLAG_INTERSECTION;
-  lineart_prepend_edge_direct(&rb->intersection_lines, result);
+  lineart_prepend_edge_direct(&rb->intersection.first, result);
   int r1, r2, c1, c2, row, col;
   if (lineart_get_edge_bounding_areas(rb, result, &r1, &r2, &c1, &c2)) {
     for (row = r1; row != r2 + 1; row++) {
@@ -2508,8 +2510,6 @@ static LineartEdge *lineart_triangle_intersect(LineartRenderBuffer *rb,
     }
   }
 
-  rb->intersection_count++;
-
   return result;
 }
 
@@ -2598,22 +2598,11 @@ static void lineart_destroy_render_data(LineartRenderBuffer *rb)
     return;
   }
 
-  rb->contour_count = 0;
-  rb->contour_managed = NULL;
-  rb->intersection_count = 0;
-  rb->intersection_managed = NULL;
-  rb->material_line_count = 0;
-  rb->material_managed = NULL;
-  rb->crease_count = 0;
-  rb->crease_managed = NULL;
-  rb->edge_mark_count = 0;
-  rb->edge_mark_managed = NULL;
-
-  rb->contours = NULL;
-  rb->intersection_lines = NULL;
-  rb->crease_lines = NULL;
-  rb->material_lines = NULL;
-  rb->edge_marks = NULL;
+  memset(&rb->contour, 0, sizeof(ListBase));
+  memset(&rb->crease, 0, sizeof(ListBase));
+  memset(&rb->intersection, 0, sizeof(ListBase));
+  memset(&rb->edge_mark, 0, sizeof(ListBase));
+  memset(&rb->material, 0,

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list