[Bf-blender-cvs] [7acf84a011b] temp_lineart_contained: LinrArt: Running line art modifier.

YimingWu noreply at git.blender.org
Thu Nov 12 08:05:59 CET 2020


Commit: 7acf84a011bc539c3a4588f83b58a674891c13d5
Author: YimingWu
Date:   Thu Nov 12 15:05:08 2020 +0800
Branches: temp_lineart_contained
https://developer.blender.org/rB7acf84a011bc539c3a4588f83b58a674891c13d5

LinrArt: Running line art modifier.

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

M	source/blender/gpencil_modifiers/intern/MOD_gpencillineart.c
M	source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c
M	source/blender/makesrna/intern/rna_material.c

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

diff --git a/source/blender/gpencil_modifiers/intern/MOD_gpencillineart.c b/source/blender/gpencil_modifiers/intern/MOD_gpencillineart.c
index 22529e46793..4e5d8f2f72c 100644
--- a/source/blender/gpencil_modifiers/intern/MOD_gpencillineart.c
+++ b/source/blender/gpencil_modifiers/intern/MOD_gpencillineart.c
@@ -160,10 +160,6 @@ static void generateStrokes(GpencilModifierData *md, Depsgraph *depsgraph, Objec
 
   bool is_render = (DEG_get_mode(depsgraph) == DAG_EVAL_RENDER);
 
-  if (ED_lineart_modifier_sync_flag_check(LRT_SYNC_IGNORE)) {
-    return;
-  }
-
   /* Check all parameters required are filled. */
   if (isModifierDisabled(md)) {
     return;
@@ -171,10 +167,10 @@ static void generateStrokes(GpencilModifierData *md, Depsgraph *depsgraph, Objec
 
   ED_lineart_compute_feature_lines_internal(depsgraph, lmd, 1);
 
-  /* If we reach here, means calculation is finished (LRT_SYNC_FRESH), we grab cache. flag
-   * reset is done by calculation function.*/
   generate_strokes_actual(md, depsgraph, ob, gpl, gpf);
 
+  ED_lineart_destroy_render_data();
+
   WM_main_add_notifier(NA_EDITED | NC_GPENCIL, NULL);
 }
 
@@ -200,6 +196,8 @@ static void bakeModifier(Main *UNUSED(bmain),
   ED_lineart_compute_feature_lines_internal(depsgraph, lmd, 1);
 
   generate_strokes_actual(md, depsgraph, ob, gpl, gpf);
+
+  ED_lineart_destroy_render_data();
 }
 
 static bool isDisabled(GpencilModifierData *md, int UNUSED(userRenderParams))
diff --git a/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c b/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c
index 093663cf4e1..7e0de165b5a 100644
--- a/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c
+++ b/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c
@@ -2527,6 +2527,8 @@ static void lineart_destroy_render_data(void)
   BLI_spin_end(&rb->lock_cuts);
   BLI_spin_end(&rb->render_data_pool.lock_mem);
 
+  BLI_spin_end(lineart_share.lock_render_status);
+
   lineart_mem_destroy(&rb->render_data_pool);
 }
 
@@ -2547,10 +2549,6 @@ void ED_lineart_destroy_render_data(void)
 
 void ED_lineart_destroy_render_data_external(void)
 {
-  if (!lineart_share.init_complete) {
-    return;
-  }
-
   while (ED_lineart_calculation_flag_check(LRT_RENDER_RUNNING)) {
     /* Wait to finish, XXX: should cancel here. */
   }
@@ -2572,12 +2570,6 @@ LineartRenderBuffer *ED_lineart_create_render_buffer(Scene *scene, LineartGpenci
 {
   /* Re-init render_buffer_shared. */
   if (lineart_share.render_buffer_shared) {
-    if (G.debug_value == 4000) {
-      printf("LRT: **** Destroy on create.\n");
-    }
-    while (ED_lineart_modifier_sync_flag_check(LRT_SYNC_CLEARING)) {
-      /* Don't race the clearing stage. */
-    }
     ED_lineart_destroy_render_data_external();
   }
 
@@ -2647,7 +2639,6 @@ LineartRenderBuffer *ED_lineart_create_render_buffer(Scene *scene, LineartGpenci
 void ED_lineart_init_locks()
 {
   if (!(lineart_share.init_complete & LRT_INIT_LOCKS)) {
-    BLI_spin_init(&lineart_share.lock_loader);
     BLI_spin_init(&lineart_share.lock_render_status);
     lineart_share.init_complete |= LRT_INIT_LOCKS;
   }
@@ -2676,59 +2667,6 @@ bool ED_lineart_calculation_flag_check(eLineartRenderStatus flag)
   return match;
 }
 
-void ED_lineart_modifier_sync_flag_set(eLineartModifierSyncStatus flag,
-                                       bool UNUSED(is_from_modifier))
-{
-  BLI_spin_lock(&lineart_share.lock_render_status);
-
-  if (flag != LRT_SYNC_IDLE) {
-    while (lineart_share.flag_sync_staus == LRT_SYNC_CLEARING) {
-      /* Waiting, no double clearing in a new call. */
-    }
-  }
-
-  lineart_share.flag_sync_staus = flag;
-
-  BLI_spin_unlock(&lineart_share.lock_render_status);
-}
-
-bool ED_lineart_modifier_sync_flag_check(eLineartModifierSyncStatus flag)
-{
-  bool match;
-  BLI_spin_lock(&lineart_share.lock_render_status);
-  match = (lineart_share.flag_sync_staus == flag);
-  BLI_spin_unlock(&lineart_share.lock_render_status);
-  return match;
-}
-
-void ED_lineart_modifier_sync_add_customer()
-{
-  BLI_spin_lock(&lineart_share.lock_render_status);
-
-  lineart_share.customers++;
-
-  BLI_spin_unlock(&lineart_share.lock_render_status);
-}
-void ED_lineart_modifier_sync_remove_customer()
-{
-  BLI_spin_lock(&lineart_share.lock_render_status);
-
-  lineart_share.customers--;
-
-  BLI_spin_unlock(&lineart_share.lock_render_status);
-}
-
-bool ED_lineart_modifier_sync_still_has_customer()
-{
-  BLI_spin_lock(&lineart_share.lock_render_status);
-
-  bool non_zero = lineart_share.customers != 0;
-
-  BLI_spin_unlock(&lineart_share.lock_render_status);
-
-  return non_zero;
-}
-
 static int lineart_occlusion_get_max_level(Depsgraph *dg)
 {
   LineartGpencilModifierData *lmd;
@@ -3708,9 +3646,9 @@ int ED_lineart_compute_feature_lines_internal(Depsgraph *depsgraph,
   Scene *scene = DEG_get_evaluated_scene(depsgraph);
   int intersections_only = 0; /* Not used right now, but preserve for future. */
 
+  ED_lineart_init_locks();
+
   if (!scene->camera) {
-    /* Release lock when early return. */
-    BLI_spin_unlock(&lineart_share.lock_loader);
     return OPERATOR_CANCELLED;
   }
 
@@ -3719,12 +3657,6 @@ int ED_lineart_compute_feature_lines_internal(Depsgraph *depsgraph,
     ED_lineart_update_render_progress(progress, message); \
   }
 
-#define LRT_CANCEL_STAGE \
-  if (ED_lineart_calculation_flag_check(LRT_RENDER_CANCELING)) { \
-    LRT_PROGRESS(100, "LRT: Finished."); \
-    return OPERATOR_FINISHED; \
-  }
-
   rb = ED_lineart_create_render_buffer(scene, lmd);
 
   /* Has to be set after render buffer creation, to avoid locking from editor undo. */
@@ -3734,7 +3666,7 @@ int ED_lineart_compute_feature_lines_internal(Depsgraph *depsgraph,
 
   rb->triangle_size = lineart_triangle_size_get(scene);
 
-  rb->max_occlusion_level = lineart_occlusion_get_max_level(depsgraph);
+  rb->max_occlusion_level = MAX2(lmd->level_start, lmd->level_end);
 
   LRT_PROGRESS(0, "LRT: Loading geometries.");
 
@@ -3742,17 +3674,12 @@ int ED_lineart_compute_feature_lines_internal(Depsgraph *depsgraph,
   lineart_main_load_geometries(
       depsgraph, scene, scene->camera, rb, lmd->calculation_flags & LRT_ALLOW_DUPLI_OBJECTS);
 
-  /** We had everything we need,
-   * Unlock parent thread, it'scene safe to run independently from now. */
-  BLI_spin_unlock(&lineart_share.lock_loader);
-
   if (!rb->vertex_buffer_pointers.first) {
     /* Nothing loaded, early return. */
     LRT_PROGRESS(100, "LRT: Finished.");
     return OPERATOR_FINISHED;
   }
 
-  LRT_CANCEL_STAGE
   LRT_PROGRESS(10, "LRT: Culling.");
 
   lineart_main_bounding_area_make_initial(rb);
@@ -3764,19 +3691,16 @@ int ED_lineart_compute_feature_lines_internal(Depsgraph *depsgraph,
 
   lineart_main_perspective_division(rb);
 
-  LRT_CANCEL_STAGE
   LRT_PROGRESS(25, "LRT: Intersections.");
 
   lineart_main_add_triangles(rb);
 
-  LRT_CANCEL_STAGE
   LRT_PROGRESS(50, "LRT: Occlusion.");
 
   if (!intersections_only) {
     lineart_main_occlusion_begin(rb);
   }
 
-  LRT_CANCEL_STAGE
   LRT_PROGRESS(75, "LRT: Chaining.");
 
   /* intersection_only is preserved for furure functions.*/
@@ -3808,13 +3732,14 @@ int ED_lineart_compute_feature_lines_internal(Depsgraph *depsgraph,
   LRT_PROGRESS(100, "LRT: Finished.");
 
 #undef LRT_PROGRESS
-#undef LRT_CANCEL_STAGE
   if (G.debug_value == 4000) {
     lineart_count_and_print_render_buffer_memory(rb);
   }
 
   ED_lineart_calculation_flag_set(LRT_RENDER_FINISHED);
 
+  ED_lineart_chain_clear_picked_flag(rb);
+
   return OPERATOR_FINISHED;
 }
 
@@ -3882,17 +3807,6 @@ void ED_lineart_gpencil_generate(Depsgraph *depsgraph,
     return;
   }
 
-  if ((!lineart_share.init_complete) || !ED_lineart_calculation_flag_check(LRT_RENDER_FINISHED)) {
-    /* cache not ready. */
-    if (G.debug_value == 4000) {
-      printf("Line art cache isn't ready!\n");
-    }
-    return;
-  }
-  else {
-    /* lock the cache, prevent rendering job from starting. */
-    BLI_spin_lock(&lineart_share.lock_render_status);
-  }
   int stroke_count = 0;
   int color_idx = 0;
 
diff --git a/source/blender/makesrna/intern/rna_material.c b/source/blender/makesrna/intern/rna_material.c
index 87d95dab2d5..d5faeecceb7 100644
--- a/source/blender/makesrna/intern/rna_material.c
+++ b/source/blender/makesrna/intern/rna_material.c
@@ -128,12 +128,12 @@ static void rna_MaterialGpencil_update(Main *bmain, Scene *scene, PointerRNA *pt
   WM_main_add_notifier(NC_GPENCIL | ND_DATA, ma);
 }
 
-static void rna_MaterialLineArt_update(Main *bmain, Scene *scene, PointerRNA *ptr)
+static void rna_MaterialLineArt_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
 {
-  rna_Material_update(bmain, scene, ptr);
-  if (ED_lineart_modifier_sync_flag_check(LRT_SYNC_IDLE)) {
-    ED_lineart_modifier_sync_flag_set(LRT_SYNC_WAITING, false);
-  }
+  Material *ma = (Material *)ptr->owner_id;
+  /* Need to tag geometry for line art modifier updates. */
+  DEG_id_tag_update(&ma->id, ID_RECALC_GEOMETRY);
+  WM_main_add_notifier(NC_MATERIAL | ND_SHADING_DRAW, ma);
 }
 
 static void rna_Material_draw_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)



More information about the Bf-blender-cvs mailing list