[Bf-blender-cvs] [8d3e2ffa075] master: DRW: Speedup: Only do batch cache request and validation once for duplis

Clément Foucault noreply at git.blender.org
Wed May 8 17:59:25 CEST 2019


Commit: 8d3e2ffa07576561d44a6f1e2aa4cccd765b5396
Author: Clément Foucault
Date:   Wed May 8 12:02:49 2019 +0200
Branches: master
https://developer.blender.org/rB8d3e2ffa07576561d44a6f1e2aa4cccd765b5396

DRW: Speedup: Only do batch cache request and validation once for duplis

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

M	source/blender/draw/intern/draw_manager.c

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

diff --git a/source/blender/draw/intern/draw_manager.c b/source/blender/draw/intern/draw_manager.c
index 773a5ec2c9c..6499957b123 100644
--- a/source/blender/draw/intern/draw_manager.c
+++ b/source/blender/draw/intern/draw_manager.c
@@ -814,6 +814,10 @@ static void drw_duplidata_load(DupliObject *dupli)
   void **value;
   if (!BLI_ghash_ensure_p(DST.dupli_ghash, DST.dupli_origin, &value)) {
     *value = MEM_callocN(sizeof(void *) * DST.enabled_engine_count, __func__);
+
+    /* TODO: Meh a bit out of place but this is nice as it is
+     * only done once per "original" object. */
+    drw_batch_cache_validate(DST.dupli_origin);
   }
   DST.dupli_datas = *(void ***)value;
 }
@@ -830,7 +834,9 @@ static void duplidata_value_free(void *val)
 static void drw_duplidata_free(void)
 {
   if (DST.dupli_ghash != NULL) {
-    BLI_ghash_free(DST.dupli_ghash, NULL, duplidata_value_free);
+    BLI_ghash_free(DST.dupli_ghash,
+                   (void (*)(void *key))drw_batch_cache_generate_requested,
+                   duplidata_value_free);
     DST.dupli_ghash = NULL;
   }
 }
@@ -1157,7 +1163,10 @@ static void drw_engines_cache_populate(Object *ob)
    * ourselves here. */
   drw_drawdata_unlink_dupli((ID *)ob);
 
-  drw_batch_cache_validate(ob);
+  /* Validation for dupli objects happen elsewhere. */
+  if (!DST.dupli_source) {
+    drw_batch_cache_validate(ob);
+  }
 
   int i = 0;
   for (LinkData *link = DST.enabled_engines.first; link; link = link->next, i++) {
@@ -1175,7 +1184,9 @@ static void drw_engines_cache_populate(Object *ob)
 
   /* TODO: in the future it would be nice to generate once for all viewports.
    * But we need threaded DRW manager first. */
-  drw_batch_cache_generate_requested(DST.dupli_source ? DST.dupli_source->ob : ob);
+  if (!DST.dupli_source) {
+    drw_batch_cache_generate_requested(ob);
+  }
 
   /* ... and clearing it here too because theses draw data are
    * from a mempool and must not be free individually by depsgraph. */
@@ -2098,15 +2109,20 @@ void DRW_render_object_iter(
       DST.dupli_parent = data_.dupli_parent;
       DST.dupli_source = data_.dupli_object_current;
       DST.ob_state = NULL;
+      drw_duplidata_load(DST.dupli_source);
 
-      drw_batch_cache_validate(ob);
-
+      if (!DST.dupli_source) {
+        drw_batch_cache_validate(ob);
+      }
       callback(vedata, ob, engine, depsgraph);
-
-      drw_batch_cache_generate_requested(DST.dupli_source ? DST.dupli_source->ob : ob);
+      if (!DST.dupli_source) {
+        drw_batch_cache_generate_requested(ob);
+      }
     }
   }
   DEG_OBJECT_ITER_END;
+
+  drw_duplidata_free();
 }
 
 /* Assume a valid gl context is bound (and that the gl_context_mutex has been acquired).



More information about the Bf-blender-cvs mailing list