[Bf-blender-cvs] [77afe859a0f] lineart-object-load: LineArt: CAS-inspired tile tree (WIP)

YimingWu noreply at git.blender.org
Mon Apr 25 10:56:16 CEST 2022


Commit: 77afe859a0fecb3b03b9879a4d7419f991dc9f81
Author: YimingWu
Date:   Fri Apr 15 22:10:11 2022 +0800
Branches: lineart-object-load
https://developer.blender.org/rB77afe859a0fecb3b03b9879a4d7419f991dc9f81

LineArt: CAS-inspired tile tree (WIP)

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

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

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

diff --git a/source/blender/gpencil_modifiers/CMakeLists.txt b/source/blender/gpencil_modifiers/CMakeLists.txt
index 6108629183c..85b9b64332e 100644
--- a/source/blender/gpencil_modifiers/CMakeLists.txt
+++ b/source/blender/gpencil_modifiers/CMakeLists.txt
@@ -17,6 +17,7 @@ set(INC
   ../windowmanager
   ../../../intern/eigen
   ../../../intern/guardedalloc
+  ../../../intern/atomic
 
   # dna_type_offsets.h in BLO_read_write.h
   ${CMAKE_BINARY_DIR}/source/blender/makesdna/intern
diff --git a/source/blender/gpencil_modifiers/intern/lineart/MOD_lineart.h b/source/blender/gpencil_modifiers/intern/lineart/MOD_lineart.h
index 830066ac0fb..d4d39c84c51 100644
--- a/source/blender/gpencil_modifiers/intern/lineart/MOD_lineart.h
+++ b/source/blender/gpencil_modifiers/intern/lineart/MOD_lineart.h
@@ -222,8 +222,11 @@ typedef struct LineartRenderBuffer {
 
   float overscan;
 
-  struct LineartBoundingArea *initial_bounding_areas;
-  unsigned int bounding_area_count;
+  struct LineartBoundingArea **initial_bounding_areas;
+  unsigned int bounding_area_initial_count;
+
+  /* Array of thread_count length for spatial locks. */
+  SpinLock *lock_bounding_areas;
 
   /* When splitting bounding areas, if there's an ortho camera placed at a straight angle, there
    * will be a lot of triangles aligned in line which can not be separated by continue subdividing
@@ -440,7 +443,7 @@ typedef struct LineartBoundingArea {
   double cx, cy;
 
   /** 1,2,3,4 quadrant */
-  struct LineartBoundingArea *child;
+  struct LineartBoundingArea *child[4];
 
   ListBase lp;
   ListBase rp;
diff --git a/source/blender/gpencil_modifiers/intern/lineart/lineart_chain.c b/source/blender/gpencil_modifiers/intern/lineart/lineart_chain.c
index b666eb677eb..5aa8085b0f3 100644
--- a/source/blender/gpencil_modifiers/intern/lineart/lineart_chain.c
+++ b/source/blender/gpencil_modifiers/intern/lineart/lineart_chain.c
@@ -459,25 +459,25 @@ static LineartBoundingArea *lineart_bounding_area_get_eci_recursive(LineartRende
                                                                     LineartBoundingArea *root,
                                                                     LineartEdgeChainItem *eci)
 {
-  if (root->child == NULL) {
+  if (root->child[0] == NULL) {
     return root;
   }
 
-  LineartBoundingArea *ch = root->child;
+  LineartBoundingArea **ch = root->child;
 #define IN_BOUND(ba, eci) \
-  ba.l <= eci->pos[0] && ba.r >= eci->pos[0] && ba.b <= eci->pos[1] && ba.u >= eci->pos[1]
+  ba->l <= eci->pos[0] && ba->r >= eci->pos[0] && ba->b <= eci->pos[1] && ba->u >= eci->pos[1]
 
   if (IN_BOUND(ch[0], eci)) {
-    return lineart_bounding_area_get_eci_recursive(rb, &ch[0], eci);
+    return lineart_bounding_area_get_eci_recursive(rb, ch[0], eci);
   }
   if (IN_BOUND(ch[1], eci)) {
-    return lineart_bounding_area_get_eci_recursive(rb, &ch[1], eci);
+    return lineart_bounding_area_get_eci_recursive(rb, ch[1], eci);
   }
   if (IN_BOUND(ch[2], eci)) {
-    return lineart_bounding_area_get_eci_recursive(rb, &ch[2], eci);
+    return lineart_bounding_area_get_eci_recursive(rb, ch[2], eci);
   }
   if (IN_BOUND(ch[3], eci)) {
-    return lineart_bounding_area_get_eci_recursive(rb, &ch[3], eci);
+    return lineart_bounding_area_get_eci_recursive(rb, ch[3], eci);
   }
 #undef IN_BOUND
   return NULL;
@@ -507,7 +507,7 @@ static void lineart_bounding_area_link_point_recursive(LineartRenderBuffer *rb,
                                                        LineartEdgeChain *ec,
                                                        LineartEdgeChainItem *eci)
 {
-  if (root->child == NULL) {
+  if (root->child[0] == NULL) {
     LineartChainRegisterEntry *cre = lineart_list_append_pointer_pool_sized(
         &root->linked_chains, &rb->render_data_pool, ec, sizeof(LineartChainRegisterEntry));
 
@@ -518,22 +518,22 @@ static void lineart_bounding_area_link_point_recursive(LineartRenderBuffer *rb,
     }
   }
   else {
-    LineartBoundingArea *ch = root->child;
+    LineartBoundingArea **ch = root->child;
 
 #define IN_BOUND(ba, eci) \
-  ba.l <= eci->pos[0] && ba.r >= eci->pos[0] && ba.b <= eci->pos[1] && ba.u >= eci->pos[1]
+  ba->l <= eci->pos[0] && ba->r >= eci->pos[0] && ba->b <= eci->pos[1] && ba->u >= eci->pos[1]
 
     if (IN_BOUND(ch[0], eci)) {
-      lineart_bounding_area_link_point_recursive(rb, &ch[0], ec, eci);
+      lineart_bounding_area_link_point_recursive(rb, ch[0], ec, eci);
     }
     else if (IN_BOUND(ch[1], eci)) {
-      lineart_bounding_area_link_point_recursive(rb, &ch[1], ec, eci);
+      lineart_bounding_area_link_point_recursive(rb, ch[1], ec, eci);
     }
     else if (IN_BOUND(ch[2], eci)) {
-      lineart_bounding_area_link_point_recursive(rb, &ch[2], ec, eci);
+      lineart_bounding_area_link_point_recursive(rb, ch[2], ec, eci);
     }
     else if (IN_BOUND(ch[3], eci)) {
-      lineart_bounding_area_link_point_recursive(rb, &ch[3], ec, eci);
+      lineart_bounding_area_link_point_recursive(rb, ch[3], ec, eci);
     }
 
 #undef IN_BOUND
diff --git a/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c b/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c
index dd08fc6493f..25b03860d0b 100644
--- a/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c
+++ b/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c
@@ -51,6 +51,38 @@
 
 #include "lineart_intern.h"
 
+#include "atomic_ops.h"
+
+typedef struct LineartIsecSingle {
+  float v1[3], v2[3];
+  LineartTriangle *tri1, *tri2;
+} LineartIsecSingle;
+typedef struct LineartIsecThread {
+  int thread_id;
+  /* Thread triangle data. */
+  /* Used to roughly spread the load. */
+  int count_pending;
+  /* An array of triangle element link nodes. */
+  LineartElementLinkNode **pending_triangle_nodes;
+  /* Count of above array. */
+  int current_pending;
+  int max_pending;
+
+  /* Thread intersection result data. */
+  LineartIsecSingle *array;
+  int current;
+  int max;
+  int count_test;
+
+  /* For individual thread reference.*/
+  LineartRenderBuffer *rb;
+} LineartIsecThread;
+typedef struct LineartIsecData {
+  LineartRenderBuffer *rb;
+  LineartIsecThread *threads;
+  int thread_count;
+} LineartIsecData;
+
 static LineartBoundingArea *lineart_edge_first_bounding_area(LineartRenderBuffer *rb,
                                                              LineartEdge *e);
 
@@ -98,6 +130,21 @@ static bool lineart_triangle_edge_image_space_occlusion(SpinLock *spl,
 
 static void lineart_add_edge_to_list(LineartRenderBuffer *rb, LineartEdge *e);
 
+static void lineart_bounding_area_link_triangle_cas(LineartRenderBuffer *rb,
+                                                    LineartBoundingArea **root_ba,
+                                                    LineartTriangle *tri,
+                                                    double *LRUB,
+                                                    int recursive,
+                                                    int recursive_level,
+                                                    bool do_intersection,
+                                                    struct LineartIsecThread *th);
+
+static void lineart_free_bounding_area_memory(LineartBoundingArea *ba,
+                                              bool recursive,
+                                              bool free_ba);
+
+static void lineart_free_bounding_area_memories(LineartRenderBuffer *rb);
+
 static LineartCache *lineart_init_cache(void);
 
 static void lineart_discard_segment(LineartRenderBuffer *rb, LineartEdgeSegment *es)
@@ -321,10 +368,11 @@ static void lineart_bounding_area_triangle_add(LineartRenderBuffer *rb,
     return;
   }
   if (ba->triangle_count >= ba->max_triangle_count) {
-    LineartTriangle **new_array = lineart_mem_acquire(
-        &rb->render_data_pool, sizeof(LineartTriangle *) * ba->max_triangle_count * 2);
+    LineartTriangle **new_array = MEM_mallocN(
+        sizeof(LineartTriangle *) * ba->max_triangle_count * 2, "new ba_triangle_array");
     memcpy(new_array, ba->linked_triangles, sizeof(LineartTriangle *) * ba->max_triangle_count);
     ba->max_triangle_count *= 2;
+    MEM_freeN(ba->linked_triangles);
     ba->linked_triangles = new_array;
   }
   ba->linked_triangles[ba->triangle_count] = tri;
@@ -342,10 +390,11 @@ static void lineart_bounding_area_line_add(LineartRenderBuffer *rb,
     return;
   }
   if (ba->line_count >= ba->max_line_count) {
-    LineartEdge **new_array = lineart_mem_acquire(&rb->render_data_pool,
-                                                  sizeof(LineartEdge *) * ba->max_line_count * 2);
+    LineartEdge **new_array = MEM_mallocN(sizeof(LineartEdge *) * ba->max_line_count * 2,
+                                          "new ba_line_array");
     memcpy(new_array, ba->linked_lines, sizeof(LineartEdge *) * ba->max_line_count);
     ba->max_line_count *= 2;
+    MEM_freeN(ba->linked_lines);
     ba->linked_lines = new_array;
   }
   ba->linked_lines[ba->line_count] = e;
@@ -3737,13 +3786,13 @@ static void lineart_triangle_intersect_in_bounding_area(LineartRenderBuffer *rb,
   double *G0 = tri->v[0]->gloc, *G1 = tri->v[1]->gloc, *G2 = tri->v[2]->gloc;
 
   /* If this is not the smallest subdiv bounding area. */
-  if (ba->child) {
-    lineart_triangle_intersect_in_bounding_area(rb, tri, &ba->child[0]);
-    lineart_triangle_intersect_in_bounding_area(rb, tri, &ba->child[1]);
-    lineart_triangle_intersect_in_bounding_area(rb, tri, &ba->child[2]);
-    lineart_triangle_intersect_in_bounding_area(rb, tri, &ba->child[3]);
-    return;
-  }
+  // if (ba->child[0]) {
+  //  lineart_triangle_intersect_in_bounding_area(rb, tri, ba->child[0], th);
+  //  lineart_triangle_intersect_in_bounding_area(rb, tri, ba->child[1], th);
+  //  lineart_triangle_intersect_in_bounding_area(rb, tri, ba->child[2], th);
+  //  lineart_triangle_intersect_in_bounding_area(rb, tri, ba->child[3], th);
+  //  return;
+  //}
 
   /* If this _is_ the smallest subdiv bounding area, then do the intersections there. */
   for (int i = 0; i < ba->triangle_count; i++) {
@@ -3826,6 +3875,12 @@ static void lineart_destroy_render_data(LineartRenderBuffer *rb)
   BLI_spin_end(&rb->lock_cuts);
   BLI_spin_end(&rb->render_dat

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list