Commit: 64ea607ce4128e49d0bf050545254b17618a4586
Author: YimingWu
Date:   Sun Aug 9 21:56:35 2020 +0800
Branches: lanpr-under-gp
https://developer.blender.org/rB64ea607ce4128e49d0bf050545254b17618a4586

LineArt: Memory sync fixes for animation rendering.

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

M       source/blender/editors/include/ED_lineart.h
M       source/blender/editors/lineart/lineart_cpu.c
M       source/blender/editors/lineart/lineart_intern.h
M       source/blender/editors/lineart/lineart_util.c
M       source/blender/editors/render/render_update.c
M       source/blender/gpencil_modifiers/intern/MOD_gpencillineart.c

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

diff --git a/source/blender/editors/include/ED_lineart.h 
b/source/blender/editors/include/ED_lineart.h
index 2124767bdf6..48e8cb80b58 100644
--- a/source/blender/editors/include/ED_lineart.h
+++ b/source/blender/editors/include/ED_lineart.h
@@ -271,6 +271,7 @@ typedef enum eLineartModifierSyncStatus {
   LRT_SYNC_WAITING = 1,
   LRT_SYNC_FRESH = 2,
   LRT_SYNC_IGNORE = 3,
+  LRT_SYNC_CLEARING = 4
 } eLineartModifierSyncStatus;
 
 typedef struct LineartSharedResource {
@@ -550,7 +551,8 @@ struct bContext;
 
 void ED_lineart_post_frame_update_external(struct bContext *C,
                                            struct Scene *s,
-                                           struct Depsgraph *dg);
+                                           struct Depsgraph *dg,
+                                           bool from_modifier);
 
 struct SceneLineart;
 
diff --git a/source/blender/editors/lineart/lineart_cpu.c 
b/source/blender/editors/lineart/lineart_cpu.c
index a4e26ae1dd2..d5dc7b215ee 100644
--- a/source/blender/editors/lineart/lineart_cpu.c
+++ b/source/blender/editors/lineart/lineart_cpu.c
@@ -385,9 +385,9 @@ static void 
lineart_occlusion_single_line(LineartRenderBuffer *rb,
                  l,
                  r,
                  ((Object *)rt->base.rl[0]->object_ref)->id.name,
-                 rt->base.rl[0]->object_ref,
+                 (int)rt->base.rl[0]->object_ref,
                  ((Object *)rl->object_ref)->id.name,
-                 rl->object_ref);
+                 (int)rl->object_ref);
         }
         if (rl->min_occ > rb->max_occlusion_level) {
           return; /* No need to caluclate any longer. */
@@ -2444,6 +2444,12 @@ void 
ED_lineart_modifier_sync_flag_set(eLineartModifierSyncStatus flag,
 {
   BLI_spin_lock(&lineart_share.lock_render_status);
 
+  if (flag != LRT_RENDER_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);
@@ -3889,7 +3895,10 @@ void SCENE_OT_lineart_bake_strokes(wmOperatorType *ot)
   ot->exec = lineart_gpencil_bake_strokes_exec;
 }
 
-void ED_lineart_post_frame_update_external(bContext *C, Scene *scene, 
Depsgraph *dg)
+void ED_lineart_post_frame_update_external(bContext *C,
+                                           Scene *scene,
+                                           Depsgraph *dg,
+                                           bool from_modifier)
 {
   if (!(scene->lineart.flags & LRT_AUTO_UPDATE)) {
     /* This way the modifier will update, removing remaing strokes in the 
viewport. */
@@ -3924,13 +3933,22 @@ void ED_lineart_post_frame_update_external(bContext *C, 
Scene *scene, Depsgraph
     }
   }
   else if (ED_lineart_modifier_sync_flag_check(LRT_SYNC_FRESH)) {
-    /* At this stage GP should have all the data. We clear the flag */
-    ED_lineart_modifier_sync_flag_set(LRT_SYNC_IDLE, false);
+    /* To avoid double clearing. */
+    ED_lineart_modifier_sync_flag_set(LRT_SYNC_CLEARING, from_modifier);
+
+    /* TODO in the future: the call below seems to cause crash (double free) 
when using eevee in
+     * SOME files, not sure why but  */
+
     /* Due to using GPencil modifiers, and the scene is updated each time some 
value is changed, we
      * really don't need to keep the buffer any longer. If in the future we 
want fast refresh on
      * parameter changes (e.g. thickness or picking different result in an 
already validated
-     * buffer), remove this call below. */
-    ED_lineart_destroy_render_data_external();
+     * buffer), remove ED_lineart_destroy_render_data_external() below. */
+    if (!from_modifier) {
+      ED_lineart_destroy_render_data_external();
+    }
+
+    /* At this stage GP should have all the data. We clear the flag */
+    ED_lineart_modifier_sync_flag_set(LRT_SYNC_IDLE, from_modifier);
   }
 }
 
diff --git a/source/blender/editors/lineart/lineart_intern.h 
b/source/blender/editors/lineart/lineart_intern.h
index 4d545a48f91..443f6606fc4 100644
--- a/source/blender/editors/lineart/lineart_intern.h
+++ b/source/blender/editors/lineart/lineart_intern.h
@@ -56,7 +56,7 @@ LineartStaticMemPoolNode *lineart_mem_new_static_pool(struct 
LineartStaticMemPoo
                                                       size_t size);
 void *lineart_mem_aquire(struct LineartStaticMemPool *smp, size_t size);
 void *lineart_mem_aquire_thread(struct LineartStaticMemPool *smp, size_t size);
-void *lineart_mem_destroy(LineartStaticMemPool *smp);
+void lineart_mem_destroy(LineartStaticMemPool *smp);
 
 void lineart_matrix_ortho_44d(double (*mProjection)[4],
                               double xMin,
diff --git a/source/blender/editors/lineart/lineart_util.c 
b/source/blender/editors/lineart/lineart_util.c
index bc5e22834c6..5dd929b9c8c 100644
--- a/source/blender/editors/lineart/lineart_util.c
+++ b/source/blender/editors/lineart/lineart_util.c
@@ -104,11 +104,12 @@ void *lineart_mem_aquire(LineartStaticMemPool *smp, 
size_t size)
 }
 void *lineart_mem_aquire_thread(LineartStaticMemPool *smp, size_t size)
 {
-  LineartStaticMemPoolNode *smpn = smp->pools.first;
   void *ret;
 
   BLI_spin_lock(&smp->lock_mem);
 
+  LineartStaticMemPoolNode *smpn = smp->pools.first;
+
   if (!smpn || (smpn->used_byte + size) > smpn->size) {
     smpn = lineart_mem_new_static_pool(smp, size);
   }
@@ -121,16 +122,12 @@ void *lineart_mem_aquire_thread(LineartStaticMemPool 
*smp, size_t size)
 
   return ret;
 }
-void *lineart_mem_destroy(LineartStaticMemPool *smp)
+void lineart_mem_destroy(LineartStaticMemPool *smp)
 {
   LineartStaticMemPoolNode *smpn;
-  void *ret = 0;
-
   while ((smpn = BLI_pophead(&smp->pools)) != NULL) {
     MEM_freeN(smpn);
   }
-
-  return ret;
 }
 
 /* 
=======================================================================[str] */
diff --git a/source/blender/editors/render/render_update.c 
b/source/blender/editors/render/render_update.c
index 4a8dd6ba720..eb3e54aedda 100644
--- a/source/blender/editors/render/render_update.c
+++ b/source/blender/editors/render/render_update.c
@@ -111,7 +111,7 @@ void ED_render_scene_update(const DEGEditorUpdateContext 
*update_ctx, int update
 #ifdef WITH_LINEART
   /* Temporary solution for updating Line Art GPencil targets. */
   if (updated) {
-    ED_lineart_post_frame_update_external(C, scene, update_ctx->depsgraph);
+    ED_lineart_post_frame_update_external(C, scene, update_ctx->depsgraph, 
false);
   }
 #endif
 
diff --git a/source/blender/gpencil_modifiers/intern/MOD_gpencillineart.c 
b/source/blender/gpencil_modifiers/intern/MOD_gpencillineart.c
index 01b472678ab..92b78b51520 100644
--- a/source/blender/gpencil_modifiers/intern/MOD_gpencillineart.c
+++ b/source/blender/gpencil_modifiers/intern/MOD_gpencillineart.c
@@ -168,7 +168,8 @@ static void generateStrokes(GpencilModifierData *md, 
Depsgraph *depsgraph, Objec
     /* Don't have data yet, update line art. Note:  
ED_lineart_post_frame_update_external will
      * automatically return when calculation is already in progress.*/
     if (is_render) {
-      ED_lineart_post_frame_update_external(NULL, 
DEG_get_evaluated_scene(depsgraph), depsgraph);
+      ED_lineart_post_frame_update_external(
+          NULL, DEG_get_evaluated_scene(depsgraph), depsgraph, true);
       while (!ED_lineart_modifier_sync_flag_check(LRT_SYNC_FRESH) ||
              !ED_lineart_calculation_flag_check(LRT_RENDER_FINISHED)) {
         /* Wait till it's done. */

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to