[Bf-blender-cvs] [992735589d7] lanpr-under-gp: LineArt: No double caching during one update, even with multiple modifiers.

YimingWu noreply at git.blender.org
Tue Sep 22 06:20:44 CEST 2020


Commit: 992735589d7808329a1ab2ba94bf2144ce8d78e2
Author: YimingWu
Date:   Tue Sep 22 12:20:07 2020 +0800
Branches: lanpr-under-gp
https://developer.blender.org/rB992735589d7808329a1ab2ba94bf2144ce8d78e2

LineArt: No double caching during one update, even with multiple modifiers.

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

M	source/blender/blenkernel/intern/collection.c
M	source/blender/blenloader/intern/readfile.c
M	source/blender/blenloader/intern/writefile.c
M	source/blender/editors/include/ED_lineart.h
M	source/blender/editors/lineart/lineart_cpu.c
M	source/blender/gpencil_modifiers/intern/MOD_gpencillineart.c
M	source/blender/makesrna/intern/rna_material.c
M	source/blender/makesrna/intern/rna_scene.c

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

diff --git a/source/blender/blenkernel/intern/collection.c b/source/blender/blenkernel/intern/collection.c
index ac21b143b4d..4d3c778058d 100644
--- a/source/blender/blenkernel/intern/collection.c
+++ b/source/blender/blenkernel/intern/collection.c
@@ -108,6 +108,7 @@ static void collection_copy_data(Main *bmain, ID *id_dst, const ID *id_src, cons
   }
 
   collection_dst->flag &= ~COLLECTION_HAS_OBJECT_CACHE;
+  collection_dst->flag &= ~COLLECTION_HAS_OBJECT_CACHE_INSTANCED;
   BLI_listbase_clear(&collection_dst->object_cache);
   BLI_listbase_clear(&collection_dst->object_cache_instanced);
 
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index c5718dca9ac..4c6a2925726 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -4155,6 +4155,7 @@ static void direct_link_collection(BlendDataReader *reader, Collection *collecti
   BKE_previewimg_blend_read(reader, collection->preview);
 
   collection->flag &= ~COLLECTION_HAS_OBJECT_CACHE;
+  collection->flag &= ~COLLECTION_HAS_OBJECT_CACHE_INSTANCED;
   collection->tag = 0;
   BLI_listbase_clear(&collection->object_cache);
   BLI_listbase_clear(&collection->object_cache_instanced);
diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c
index 7719f71da63..d52958c10ff 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -1409,6 +1409,7 @@ static void write_collection(BlendWriter *writer, Collection *collection, const
   if (collection->id.us > 0 || BLO_write_is_undo(writer)) {
     /* Clean up, important in undo case to reduce false detection of changed data-blocks. */
     collection->flag &= ~COLLECTION_HAS_OBJECT_CACHE;
+    collection->flag &= ~COLLECTION_HAS_OBJECT_CACHE_INSTANCED;
     collection->tag = 0;
     BLI_listbase_clear(&collection->object_cache);
     BLI_listbase_clear(&collection->object_cache_instanced);
diff --git a/source/blender/editors/include/ED_lineart.h b/source/blender/editors/include/ED_lineart.h
index f9eef65d730..17068439a83 100644
--- a/source/blender/editors/include/ED_lineart.h
+++ b/source/blender/editors/include/ED_lineart.h
@@ -315,6 +315,8 @@ typedef struct LineartSharedResource {
   SpinLock lock_render_status;
   eLineartRenderStatus flag_render_status;
   eLineartModifierSyncStatus flag_sync_staus;
+  /** count of pending modifiers that is waiting for the data. */
+  int customers;
 
   int thread_count;
 
@@ -563,6 +565,9 @@ bool ED_lineart_calculation_flag_check(eLineartRenderStatus flag);
 
 void ED_lineart_modifier_sync_flag_set(eLineartModifierSyncStatus flag, bool is_from_modifier);
 bool ED_lineart_modifier_sync_flag_check(eLineartModifierSyncStatus flag);
+void ED_lineart_modifier_sync_add_customer();
+void ED_lineart_modifier_sync_remove_customer();
+bool ED_lineart_modifier_sync_still_has_customer();
 
 int ED_lineart_compute_feature_lines_internal(struct Depsgraph *depsgraph,
                                               const int show_frame_progress);
diff --git a/source/blender/editors/lineart/lineart_cpu.c b/source/blender/editors/lineart/lineart_cpu.c
index eea6b7174a6..e47844c3dce 100644
--- a/source/blender/editors/lineart/lineart_cpu.c
+++ b/source/blender/editors/lineart/lineart_cpu.c
@@ -1474,7 +1474,8 @@ static void lineart_vert_transform(
   mul_v4_m4v3_db(rv->fbcoord, mvp_mat, co);
 }
 
-static void lineart_geometry_object_load(Object *ob,
+static void lineart_geometry_object_load(Depsgraph *dg,
+                                         Object *ob,
                                          double (*mv_mat)[4],
                                          double (*mvp_mat)[4],
                                          LineartRenderBuffer *rb,
@@ -1509,7 +1510,7 @@ static void lineart_geometry_object_load(Object *ob,
       ob->type == OB_FONT) {
 
     if (ob->type == OB_MESH) {
-      use_mesh = ob->data;
+      use_mesh = DEG_get_evaluated_object(dg, ob)->data;
     }
     else {
       use_mesh = BKE_mesh_new_from_object(NULL, ob, false);
@@ -1785,7 +1786,7 @@ static void lineart_main_load_geometries(Depsgraph *depsgraph,
   DEG_OBJECT_ITER_BEGIN (depsgraph, ob, flags) {
     int usage = ED_lineart_object_collection_usage_check(scene->master_collection, ob);
 
-    lineart_geometry_object_load(ob, view, proj, rb, usage);
+    lineart_geometry_object_load(depsgraph, ob, view, proj, rb, usage);
 
     if (ED_lineart_calculation_flag_check(LRT_RENDER_CANCELING)) {
       return;
@@ -2721,6 +2722,34 @@ bool ED_lineart_modifier_sync_flag_check(eLineartModifierSyncStatus flag)
   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;
@@ -3914,8 +3943,7 @@ void ED_lineart_gpencil_generate_from_chain(Depsgraph *UNUSED(depsgraph),
     /* lock the cache, prevent rendering job from starting */
     BLI_spin_lock(&lineart_share.lock_render_status);
   }
-  static int tempnum = 0;
-  tempnum++;
+  int stroke_count = 0;
   int color_idx = 0;
 
   Object *orig_ob = NULL;
@@ -3994,10 +4022,11 @@ void ED_lineart_gpencil_generate_from_chain(Depsgraph *UNUSED(depsgraph),
     }
     BKE_gpencil_stroke_geometry_update(gps);
     MEM_freeN(stroke_data);
+    stroke_count++;
   }
 
   if (G.debug_value == 4000) {
-    printf("LRT: Generated strokes.\n");
+    printf("LRT: Generated %d strokes.\n", stroke_count);
   }
   /* release render lock so cache is free to be manipulated. */
   BLI_spin_unlock(&lineart_share.lock_render_status);
@@ -4233,6 +4262,9 @@ void ED_lineart_post_frame_update_external(bContext *C,
                                            Depsgraph *dg,
                                            bool from_modifier)
 {
+  if (G.debug_value == 4000) {
+    printf("LRT: ---- Post frame update (%d).\n", 0);
+  }
   if (!(scene->lineart.flags & LRT_AUTO_UPDATE)) {
     /* This way the modifier will update, removing remaing strokes in the viewport. */
     if (ED_lineart_modifier_sync_flag_check(LRT_SYNC_WAITING)) {
@@ -4271,10 +4303,17 @@ void ED_lineart_post_frame_update_external(bContext *C,
     }
   }
   else if (ED_lineart_modifier_sync_flag_check(LRT_SYNC_FRESH)) {
+    bool is_render = (DEG_get_mode(dg) == DAG_EVAL_RENDER);
+
+    /* No double caching during rendering. */
+    if (ED_lineart_modifier_sync_still_has_customer()) {
+      return;
+    }
+
     /* This code path is not working with motion blur on "render animation". not sure why, but here
      * if we retain the data and restore the flag, results will be correct. (The wrong
      * clearing happens when dg->mode == DAG_EVAL_VIEWPORT) so can't really catch it there.) */
-    if (scene->eevee.flag & SCE_EEVEE_MOTION_BLUR_ENABLED) {
+    if (is_render && (scene->eevee.flag & SCE_EEVEE_MOTION_BLUR_ENABLED)) {
       ED_lineart_modifier_sync_flag_set(LRT_SYNC_IDLE, from_modifier);
       return;
     }
@@ -4291,7 +4330,7 @@ void ED_lineart_post_frame_update_external(bContext *C,
      * buffer), remove ED_lineart_destroy_render_data_external() below.*/
     if (!from_modifier) {
       if (G.debug_value == 4000) {
-        printf("LRT: ---- Destroy on update (%d).\n", DEG_get_mode(dg));
+        printf("LRT: ---- Destroy on update (%d).\n", is_render);
       }
 
       ED_lineart_destroy_render_data_external();
diff --git a/source/blender/gpencil_modifiers/intern/MOD_gpencillineart.c b/source/blender/gpencil_modifiers/intern/MOD_gpencillineart.c
index ba75b615d05..46ab74a8b28 100644
--- a/source/blender/gpencil_modifiers/intern/MOD_gpencillineart.c
+++ b/source/blender/gpencil_modifiers/intern/MOD_gpencillineart.c
@@ -246,7 +246,7 @@ static void bakeModifier(Main *UNUSED(bmain),
   if (scene->lineart.flags & LRT_AUTO_UPDATE) {
     if (ED_lineart_modifier_sync_flag_check(LRT_SYNC_IDLE)) {
       /* Need to run it once again. */
-      ED_lineart_modifier_sync_flag_set(LRT_SYNC_WAITING, 1);
+      ED_lineart_modifier_sync_flag_set(LRT_SYNC_WAITING, true);
       BLI_spin_lock(&lineart_share.lock_loader);
       ED_lineart_compute_feature_lines_background(depsgraph, 1);
       /* Wait for loading finish */
@@ -279,26 +279,17 @@ static void updateDepsgraph(GpencilModifierData *md,
   DEG_add_object_relation(ctx->node, ctx->object, DEG_OB_COMP_TRANSFORM, "Line Art Modifier");
 
   LineartGpencilModifierData *lmd = (LineartGpencilModifierData *)md;
-  if (lmd->source_type == LRT_SOURCE_OBJECT && lmd->source_object) {
-    DEG_add_object_relation(
-        ctx->node, lmd->source_object, DEG_OB_COMP_GEOMETRY, "Line Art Modifier");
-    DEG_add_object_relation(
-        ctx->node, lmd->source_object, DEG_OB_COMP_PARAMETERS, "Line Art Modifier");
-  }
-  else {
-    FOREACH_COLLECTION_VISIBLE_OBJECT_RECURSIVE_BEGIN (ctx->scene->master_collection, ob, mode) {
-      if (ob->type == OB_MESH || ob->type == OB_MBALL || ob->type == OB_CURVE ||
-          ob->type == OB_SURF || ob->type == OB_FONT) {
-        if (!(ob->lineart.usage & COLLECTION_LRT_EXCLUDE)) {
-          DEG_add_object_relation(ctx->node, ob, DEG_OB_COMP_GEOMETRY, "Line Art Modifier");
-          DEG_add_object_relation(ctx->node, ob, DEG_OB_COMP_PARAMETERS, "Line Art Modifier");
-        }
-      }
+
+  FOREACH_COLLECTION_VISIBLE_OBJECT_RECURSIVE_BEGIN (ctx->scene->master_collection, ob, mode) {
+    if (ob->type == OB_MESH || ob->type == OB_MBALL || ob->type == OB_CURVE ||
+        ob->type == OB_SURF || ob->type == OB_FONT) {
+      // if (!(ob->lineart.usage & OBJECT_LRT_EXCLUDE)) {
+      DEG_add_object_relation(ctx->node,

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list